Example #1
0
        public User Authenticate2(string username, string password)
        {
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var user = DbContext.Users.SingleOrDefault(x => x.Username == username);

            // check if username exists
            if (user == null)
            {
                return(null);
            }
            if (user.IsActive == false)
            {
                return(null);
            }

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

            // authentication successful
            return(user);
        }