Implement password authentication

This commit is contained in:
2023-05-31 15:17:00 +02:00
parent 5ed74260a8
commit 652541cd59
6 changed files with 133 additions and 1 deletions

View File

@ -23,6 +23,18 @@ impl User {
pub fn id(&self) -> UserID {
UserID(self.id)
}
pub fn check_password(&self, password: &str) -> bool {
self.password
.as_deref()
.map(|hash| {
bcrypt::verify(password, hash).unwrap_or_else(|e| {
log::error!("Failed to validate password! {}", e);
false
})
})
.unwrap_or(false)
}
}
#[derive(Insertable)]