public Response <UserDTO> ChangePassword(ChangePasswordRequestDTO user) { try { using (VDEntities entities = new VDEntities()) { User userDB = entities.Users.Where(x => x.ID == user.UserID).FirstOrDefault(); if (userDB == null) { return(new Response <UserDTO>(false, "User not found.", null)); } if (!userDB.Password.Equals(user.OldPassword)) { return(new Response <UserDTO>(false, "Old password doesn't match.", null)); } else { userDB.Password = user.NewPassword; entities.SaveChanges(); return(new Response <UserDTO>(true, "Password change successfully.", null)); } } } catch (Exception e) { return(new Response <UserDTO>(false, GetMessageFromExceptionObject(e), null)); } }
public IActionResult ChangePassword([FromBody] ChangePasswordRequestDTO model) { try { _accountService.ChangePasswordAsync(model.UserId, model.OldPassword, model.NewPassword); return(Ok("The password is changed successfully.")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult ChangePassword([FromBody] ChangePasswordRequestDTO request) { var LoginCredential = _context.LoginCredentials.Where(x => x.UserLoginID == request.UserLoginID && x.Password == request.OldPassword).FirstOrDefault(); if (LoginCredential == null) { return(Content(HttpStatusCode.Unauthorized, new { code = ErrorCode.INVALID_OLD_PASSWORD })); } LoginCredential.Password = request.Password; _context.Entry(LoginCredential).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(Ok()); }
public UserResponseDTO ChangePassword(ChangePasswordRequestDTO requestDTO) { User user = this.FindOneByUuidOrThrow(new UserPrincipal(this._httpContextAccessor.HttpContext).uuid); if (!BCrypt.Net.BCrypt.Verify(requestDTO.oldPassword, user.password)) { throw new EntityNotFoundException("The current password does not match!", GeneralConsts.MICROSERVICE_NAME); } if (!requestDTO.newPassword.Equals(requestDTO.confirmNewPassword)) { throw new EntityNotFoundException("New passwords must be the same!", GeneralConsts.MICROSERVICE_NAME); } user = this._queryExecutor.Execute <User>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.CHANGE_PASSWORD(user.uuid, BCrypt.Net.BCrypt.HashPassword(requestDTO.newPassword)), this._modelMapper.MapToUserAfterUpdate); return(this._autoMapper.Map <UserResponseDTO>(user)); }
public ResponseDTO ChangePassword(ChangePasswordRequestDTO request) { string funcName = "ChangePassword"; Logger.Logger.FuncOpen(clsName, funcName, "request", JsonConvert.SerializeObject(request)); ResponseDTO res = new ResponseDTO(); using (MarvelBLL objMarvelBLL = new MarvelBLL()) { try { APICredentialsBLL credentialsBLL = new APICredentialsBLL(); credentialsBLL.UserName = request.APICredentials.APIUserName; credentialsBLL.Password = request.APICredentials.APIPassword; if (!new CommonMethods().ValidateRequest(credentialsBLL)) { res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ResponseMessages.InvalidCredentials; } else if (request.UserID <= 0) { res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ResponseMessages.InvalidUser; } else if (string.IsNullOrWhiteSpace(request.UserID.ToString()) || string.IsNullOrWhiteSpace(request.CurrentPassword) || string.IsNullOrWhiteSpace(request.NewPassword)) { res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ResponseMessages.InvalidData; } else { APICredentialsBLL credentials = new APICredentialsBLL(); credentials.UserName = request.UserID.ToString(); credentials.Password = request.CurrentPassword; if (new UsersBLL().CheckPassword(objMarvelBLL, credentials)) { APICredentialsBLL credential = new APICredentialsBLL(); credential.UserName = request.UserID.ToString(); credential.Password = request.NewPassword; if (new UsersBLL().ChangePassword(objMarvelBLL, credential)) { res.ResponseCode = ResponseCodes.Success; res.ResponseMessage = ResponseMessages.Success; } else { res.ResponseCode = ResponseCodes.Success; res.ResponseMessage = ResponseMessages.InvalidUser; } } else { res.ResponseCode = ResponseCodes.Success; res.ResponseMessage = ResponseMessages.IncorrectCurrent; } res.ResponseData = new ResponseData(); } } catch (Exception ex) { Logger.Logger.WriteErrorLog(clsName, funcName, ex); res.ResponseCode = ResponseCodes.Failed; res.ResponseMessage = ex.Message; } } Logger.Logger.Information(clsName, funcName, "Response", JsonConvert.SerializeObject(res)); Logger.Logger.FuncClose(clsName, funcName); return(res); }
public ActionResult <UserResponseDTO> HandleChangePassword(ChangePasswordRequestDTO requestDTO) { return(Ok(this._userService.ChangePassword(requestDTO))); }
/// <summary> /// This call changes the password of connected user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordRequest">Password request to change</param> /// <returns>Task of ApiResponse</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > PasswordManagerChangePasswordAsyncWithHttpInfo(ChangePasswordRequestDTO passwordRequest) { // verify the required parameter 'passwordRequest' is set if (passwordRequest == null) { throw new ApiException(400, "Missing required parameter 'passwordRequest' when calling PasswordManagerApi->PasswordManagerChangePassword"); } var localVarPath = "/api/PasswordManager/ChangePassword"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (passwordRequest != null && passwordRequest.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(passwordRequest); // http body (model) parameter } else { localVarPostBody = passwordRequest; // byte array } // authentication (Authorization) required if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("Authorization"))) { localVarHeaderParams["Authorization"] = Configuration.GetApiKeyWithPrefix("Authorization"); } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("PasswordManagerChangePassword", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null)); }
/// <summary> /// This call changes the password of connected user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordRequest">Password request to change</param> /// <returns>Task of void</returns> public async System.Threading.Tasks.Task PasswordManagerChangePasswordAsync(ChangePasswordRequestDTO passwordRequest) { await PasswordManagerChangePasswordAsyncWithHttpInfo(passwordRequest); }
/// <summary> /// This call changes the password of connected user /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="passwordRequest">Password request to change</param> /// <returns></returns> public void PasswordManagerChangePassword(ChangePasswordRequestDTO passwordRequest) { PasswordManagerChangePasswordWithHttpInfo(passwordRequest); }