Exemplo n.º 1
0
        public void ChangePassword(ChangePasswordModel model)
        {
            try
            {
                // Validate supplied details
                _authenticationValidator.ValidateChangePassword(model);

                // Get user
                User user = _userRepository.ReadUser(model.TenantId, model.UserId);

                // Get encrypted password
                int    saltSize   = _authenticationConfigurationService.GetPasswordSaltSize(model.TenantId);
                byte[] salt       = _securityService.CreateSalt(saltSize);
                byte[] saltedHash = _securityService.EncryptPassword(model.NewPassword, salt);

                // Update user details
                user.Confirmed           = true;
                user.PasswordSaltedHash  = _stringService.GetString(saltedHash);
                user.PasswordSalt        = _stringService.GetString(salt);
                user.LockedOut           = false;
                user.LastPasswordFailure = null;
                user.PasswordFailures    = 0;
                user.PasswordChanged     = DateTime.UtcNow;

                // Change user's password
                _userRepository.UpdateUser(user);
            }
            catch (UserLockedOutException)
            {
                Logoff();
                throw;
            }
        }