示例#1
0
        public async Task <AuthenticationResult> AuthenticateUserAsync(string username,
                                                                       string password)
        {
            var result = new AuthenticationResult
            {
                FoundUser       = false,
                PasswordIsValid = false
            };

            var lookupUser = await DbSet
                             .Where(_ => _.Username == username && _.IsDeleted == false)
                             .SingleOrDefaultAsync();

            if (lookupUser != null)
            {
                result.FoundUser       = true;
                result.PasswordIsValid =
                    _passwordHasher.VerifyHashedPassword(lookupUser.PasswordHash, password);
                if (result.PasswordIsValid)
                {
                    result.User           = _mapper.Map <Model.User, User>(lookupUser);
                    lookupUser.LastAccess = _dateTimeProvider.Now;
                    await SaveAsync();
                }
            }
            return(result);
        }
        public async Task <AuthenticationResult> AuthenticateUserAsync(string username,
                                                                       string password,
                                                                       string culture)
        {
            var result = new AuthenticationResult
            {
                FoundUser       = false,
                PasswordIsValid = false
            };

            var lookupUser = await DbSet
                             .Where(_ => _.Username == username && !_.IsDeleted)
                             .SingleOrDefaultAsync();

            if (lookupUser != null)
            {
                result.FoundUser       = true;
                result.PasswordIsValid =
                    _passwordHasher.VerifyHashedPassword(lookupUser.PasswordHash, password);
                if (result.PasswordIsValid)
                {
                    result.User           = _mapper.Map <Model.User, User>(lookupUser);
                    lookupUser.LastAccess = _dateTimeProvider.Now;

                    if (culture != Culture.DefaultName)
                    {
                        // if the user is using a non-default culture, update their record
                        lookupUser.Culture = culture;
                    }

                    await SaveAsync();
                }
            }
            return(result);
        }