public int modificarPassword(PasswordModify pw) { GestorValidarPassword gVPassword = new GestorValidarPassword(); //Modificar contraseña y resetear el token return(gVPassword.modificarPassdesdeApp(pw)); }
public ApiResult Modify([FromBody] PasswordModify model) { //此处调用的是Check的重写方法,因为需验证是否操作的是本人的账户 result = AccessToken.Check(model.access_token, "api/password/modify", model.ID); if (result == null) { #region 参数验证 result = ParameterCheck.CheckParameters(model); if (result != null) { return(result); } if (model.NewPwd == model.OldPwd) { return(Error("新密码不能与原密码相同!")); } #endregion #region 逻辑操作 string old_pwd = model.OldPwd.ToString().Trim(); string new_pwd = model.NewPwd.ToString().Trim(); var accountlist = from T_Account in db.T_Account where (T_Account.AccountID == model.ID && T_Account.Password == old_pwd) select T_Account; if (accountlist.Any()) { try { T_Account accountmodel = db.T_Account.Find(model.ID); accountmodel.Password = new_pwd; db.SaveChanges(); return(Success("修改密码成功")); } catch { return(Error("修改密码失败")); } } else { return(Error("原密码输入错误")); } #endregion } return(result); }
public IActionResult ModifyClientPassword(PasswordModify data) { Client client = GetClient(); if (client == null) { return(Unauthorized()); } if (string.IsNullOrEmpty(data.Password)) { return(BadRequest(new { message = "Blogas slaptažodis." })); } if (!BCrypt.Net.BCrypt.Verify(data.CurrentPassword, client.Password)) { return(BadRequest(new { message = "Neteisingas dabartinis slaptažodis." })); } client.Password = BCrypt.Net.BCrypt.HashPassword(data.Password); _context.SaveChanges(); return(Ok(new { message = "Slaptažodis atnaujintas." })); }