Example #1
0
        public bool ValidateUsernameAndPassword(string username, string password)
        {
            if (string.IsNullOrEmpty(password))
            {
                return(false);
            }

            var user = FindUserByUsername(username);

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

            var currentPassword = PasswordHelpers.DerivePasswordFromPasswordHash(user.Password);
            var currentSalt     = PasswordHelpers.DeriveSaltFromPasswordHash(user.Password);

            if (currentPassword == null || currentSalt == null)
            {
                return(false);
            }

            var providedPasswordHash = PasswordHelpers.HashPassword(password, currentSalt);

            if (user.Password.Length != providedPasswordHash.Length)
            {
                return(false);
            }

            return(providedPasswordHash.SequenceEqual(user.Password));
        }
        public override Task <int> AddAsync(UserModel model)
        {
            model.Password = PasswordHelpers.HashPassword(model.Password);
            var resultId = base.AddAsync(model);

            model.Password = string.Empty;
            return(resultId);
        }
Example #3
0
        public static AppUser New(string password)
        {
            string salt;
            string hash = PasswordHelpers.HashPassword(password, out salt);

            return(new AppUser()
            {
                PasswordHash = hash,
                PasswordSalt = salt,
                Id = Guid.NewGuid().ToString()
            });
        }
Example #4
0
 public void SetUserPassword(User user, string password)
 {
     user.Password = PasswordHelpers.HashPassword(password);
 }
Example #5
0
 public async Task <bool> ChangePassword(int userId, string newPassword, string token)
 {
     newPassword = PasswordHelpers.HashPassword(newPassword);
     return(await UnitOfWork.ResetTickets.ChangePasswordAsync(userId, newPassword, token));
 }