public static async Task ChangePassword(Account account, AccountChangePasswordRequest request) { if (!account.IsEqualPassword(request.Password)) { throw new Error400BadRequest <Account>("Mật khẩu không chính xác"); } if (request.Password == request.NewPassword) { throw new Error400BadRequest <Account>("Mật khẩu mới không được trùng"); } var newPassword = CryptoHelper.Encrypt(request.NewPassword); await AccountDataAccess.ChangePassword(account, newPassword); }
/// <summary> /// /// </summary> /// <param name="ID"></param> /// <param name="userId"></param> /// <param name="msg"></param> /// <param name="CurrentPassword"></param> /// <param name="NewPassword"></param> /// <returns></returns> public bool ChangePassword(string ID, string userId, ref string msg, string CurrentPassword, string NewPassword) { try { AccountChangePasswordRequest Para = new AccountChangePasswordRequest(); Para.ID = ID; Para.CreatedUser = userId; Para.OldPassword = CommonHelper.GetSHA512(CurrentPassword); Para.NewPassword = CommonHelper.GetSHA512(NewPassword); NSLog.Logger.Info("ChangePassword_Request: ", Para); var result = (NSApiResponse)ApiResponse.Post <NSApiResponse>(Commons.ClientSideMyProfileChangePassword, null, Para); NSLog.Logger.Info("ChangePassword_Response: ", result); if (result != null) { if (result.Success) { return(true); } else { msg = result.Message; NSLog.Logger.Info("ChangePassword_Response: ", result.Message); return(false); } } else { NSLog.Logger.Info("ChangePassword_Response: ", result); return(false); } } catch (Exception e) { msg = e.Message.ToString(); NSLog.Logger.Error("ChangePassword_Fail: ", e); return(false); } }
public async Task <IActionResult> ChangePassword([FromBody] AccountChangePasswordRequest request) { await AccountBusiness.ChangePassword(User.Account(), request); return(NoContent()); }