aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers/UserAuthenticationHandler.cs
blob: 8f6680530152ca7212b09b6eab4aa7356b52399e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;

namespace MediaBrowser.Api.HttpHandlers
{
    class UserAuthenticationHandler : BaseSerializationHandler<AuthenticationResult>
    {
        protected override async Task<AuthenticationResult> GetObjectToSerialize()
        {
            Guid userId = Guid.Parse(await GetFormValue("userid").ConfigureAwait(false));
            User user = Kernel.Instance.Users.First(u => u.Id == userId);

            string password = await GetFormValue("password").ConfigureAwait(false);

            return new AuthenticationResult()
            {
                Success = Kernel.GetMD5(password).Equals(user.Password)
            }; 
        }
    }
}