示例#1
0
        public async Task <string> Login(string email, string password)
        {
            var user = await _userRepository.GetAsync(email);

            if (user == null || !_passwordHashService.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                throw new InvalidUserCredentialsException();
            }

            return(_jwtTokenService.CreateUserToken(user));
        }
        public async Task <User> Login(string username, string password)
        {
            var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);

            if (user == null)
            {
                return(null);
            }

            if (!_hashService.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            return(user);
        }
示例#3
0
        public async Task <User> Authenticate(string userId, string password)
        {
            if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var user = await _userDbOperations.GetAsync(e => e.UserId == userId).ConfigureAwait(false);

            // check if userId exists
            if (user == null)
            {
                return(null);
            }

            // check if password is correct
            if (!_passwordHashService.VerifyPasswordHash(password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            // authentication successful
            return(user);
        }