public IActionResult UpdateUserPassword([FromBody] UpdatePasswordRequestModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = GetUserMasterDetails(); if (result == null) { return(StatusCode(500)); } var userOldPassword = _passwordHashingHelper.HashValues(model.OldPassword, _passwordHashingHelper.GetSaltFromString(result.Salt)); if (!string.Equals(result.UserPassword, userOldPassword)) { return(BadRequest("Update failed")); } var(salt, userNewPassword) = _passwordHashingHelper.GetHashedPassword(model.NewPassword); result.UserPassword = userNewPassword; result.Salt = salt; Repo.UpdateMasterInformation(result); var saveResult = Repo.SaveData(); if (saveResult == 3) { return(BadRequest()); } return(Ok("Password Updated!")); }
public IActionResult CreateToken([FromBody] TokenRequestModel requestModelModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var details = Repo.GetUserMaster(requestModelModel.UserEmail); if (details == null) { return(BadRequest("User validation failed")); } var hashedPassword = _passwordHashingHelper.HashValues(requestModelModel.Password, _passwordHashingHelper.GetSaltFromString(details.Salt)); if (!string.Equals(hashedPassword, details.UserPassword)) { return(BadRequest("User validation failed")); } var token = TokenHandler.Create(requestModelModel.UserEmail, AppSettings.Value.SigningKey); if (string.IsNullOrEmpty(token)) { return(StatusCode(500)); } var tokenModel = new TokenResponseModel() { UserEmail = requestModelModel.UserEmail, BearerToken = token }; return(Ok(tokenModel)); }