This commit is contained in:
JMARyA 2024-09-11 11:30:05 +02:00
parent edfb2da790
commit abaa9f12c9
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 114 additions and 105 deletions

View file

@ -71,15 +71,13 @@ impl User {
}
/// Change the password of a `User`
pub async fn passwd(&mut self, old: &str, new: &str) -> Result<(), ()> {
pub async fn passwd(self, old: &str, new: &str) -> Result<(), ()> {
if self.verify_pw(old) {
self.update(&json!(
{
"password": bcrypt::hash(new, bcrypt::DEFAULT_COST).unwrap()
}
))
.await
.map_err(|_| ())?;
self.change()
.password(bcrypt::hash(new, bcrypt::DEFAULT_COST).unwrap())
.update()
.await
.map_err(|_| ())?;
return Ok(());
}