public async Task <IActionResult> UpdatePassword(long id, PasswordStruct pwstruct) { var user = await _userService.UpdatePassword(id, pwstruct.newpassword); if (user == null) { return(BadRequest(new { message = "ID not valid" })); } return(Ok(user)); }
public async Task <ActionResult <bool> > ChangePassword(int id, PasswordStruct passwordStruct) { Person person = await _context.Person.FindAsync(id); int DbId = 0; foreach (var tempperson in _context.Person) { if (tempperson.UserName.Equals(passwordStruct.username)) { DbId = tempperson.Id; } } if (!person.Password.Equals(passwordStruct.oldPassword)) { return(false); } if (DbId != id) { return(false); } person.Password = passwordStruct.newPassword; try { await _context.SaveChangesAsync(); return(true); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(false); } else { throw; } } }
public ActionResult <VerificationStruct> ChangePassword(int session, string newpassword) { var sessionstruct = new SessionStruct() { SessionNo = session }; sessionstruct.User = sessionstruct.GetUser(Sessions); if (sessionstruct.User.Id != 0) { var password = new PasswordStruct() { UserId = sessionstruct.User.Id }; password.GetLastPasswordNotTemporary(context); if (password.Password == Cryptography.Encrypt(newpassword)) { return new VerificationStruct() { Answer = false, Message = new Dictionary <string, string>() { ["Message"] = "New password should not be equal to previous." } } } ; password.Password = newpassword; password.Save(context); } return(new VerificationStruct() { Answer = true, Message = new Dictionary <string, string>() { ["Message"] = "Password was successfully changed." } }); } }