diff options
author | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2020-01-29 20:45:21 -0500 |
---|---|---|
committer | Kjetil Orbekk <kjetil.orbekk@gmail.com> | 2020-01-29 20:45:21 -0500 |
commit | cbf64a8a5c7d748722369a2ec47c1230650d7b88 (patch) | |
tree | ddb11ce3d1035aeb69fbe47dcda35e8a3876c1f3 /src/models.rs | |
parent | c8db39dea2cf50dd1fa6c499600e09818b8db44a (diff) |
authentication
Diffstat (limited to 'src/models.rs')
-rw-r--r-- | src/models.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/models.rs b/src/models.rs index 8bee887..28a8b65 100644 --- a/src/models.rs +++ b/src/models.rs @@ -1,5 +1,7 @@ +use crate::error::Error; use crate::schema::config; use crate::schema::users; +use bcrypt; #[derive(Insertable, Queryable)] #[table_name = "config"] @@ -11,16 +13,20 @@ pub struct Config<'a> { #[derive(Insertable, Queryable)] #[table_name = "users"] -pub struct User<'a> { - pub username: &'a str, - password: &'a str, +pub struct User { + pub username: String, + password: String, } -impl<'a> User<'a> { - pub fn new(username: &'a str, password: &'a str) -> User<'a> { +impl User { + pub fn new(username: &str, password: &str) -> User { User { - username: username, - password: password, + username: username.to_string(), + password: password.to_string(), } } + + pub fn verify(&self, password: &str) -> Result<bool, Error> { + bcrypt::verify(password, &self.password).map_err(|e| From::from(e)) + } } |