Implement password authentication
This commit is contained in:
@ -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)]
|
||||
|
Reference in New Issue
Block a user