Ejemplo n.º 1
0
        protected override Task <CreateNewPasswordResponseDto> ExecuteAsync(CreateNewPasswordRequestDto request, RequestContext context)
        {
            // Get the secret
            var secret = _newPasswordSecretRepository.GetValidSecret(request.Secret);

            // Check the expiration of the secret
            if (secret.ExpirationTime < _timeService.Now)
            {
                throw new RequestException(_textService.Error_CouldNotRefreshPassword);
            }

            // Get profile for the provided secret
            var profile = _uniwikiContext.Profiles.Find(secret.ProfileId);

            // Hash the password
            var password = _hashService.HashPassword(request.NewPassword);

            // Change password
            _profileRepository.ChangePassword(profile, password.hashedPassword, password.salt);

            // Invalidate the secret
            _newPasswordSecretRepository.InvalidateSecrets(profile.Id);

            // Create response
            var result = new CreateNewPasswordResponseDto();

            return(Task.FromResult(result));
        }
Ejemplo n.º 2
0
        protected override Task <ChangePasswordResponseDto> ExecuteAsync(ChangePasswordRequestDto request, RequestContext context)
        {
            // Get the user
            var profile = _uniwikiContext.Profiles.Single(p => p.Id == context.UserId !.Value);

            // Hash the password
            var oldPassword = _hashService.HashPassword(request.OldPassword, profile.PasswordSalt);

            // Check if old passwords match
            if (profile.Password != oldPassword)
            {
                throw new RequestException(_textService.Error_OldPasswordsDontMatch);
            }

            // Hash the password
            var newPassword = _hashService.HashPassword(request.NewPassword);

            // Change the password
            _profileRepository.ChangePassword(profile, newPassword.hashedPassword, newPassword.salt);

            // Create response
            var response = new ChangePasswordResponseDto();

            return(Task.FromResult(response));
        }
Ejemplo n.º 3
0
 public HttpResponseMessage ChangePassword(ChangePasswordDTO pwd)
 {
     try
     {
         repository.ChangePassword(pwd);
         return(ResponseWrapper.SuccessResponse("修改成功!"));
     }
     catch (Exception e)
     {
         return(ResponseWrapper.ExceptionResponse(e));
     }
 }
Ejemplo n.º 4
0
 public string ChangePassword(string newPassword)
 {
     try
     {
         var oRetMsg = oProfileRepository.ChangePassword(new DoctorPasswordModel {
             doctorID = SessionHandler.UserInfo.Id, password = newPassword
         });
         return(oRetMsg.message);
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }