From fb205cd397f1bc3495e6754d83a3cec52caf03d3 Mon Sep 17 00:00:00 2001 From: Emi Tatsuo Date: Thu, 19 Nov 2020 16:07:52 -0500 Subject: [PATCH] Switched from bcrypt to argon --- Cargo.toml | 2 +- src/user_management/mod.rs | 14 +++++++------- src/user_management/user.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e38e3bf..9027145 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ mime_guess = { version = "2.0.3", optional = true } sled = { version = "0.34.6", optional = true } bincode = { version = "1.3.1", optional = true } serde = { version = "1.0", optional = true } -bcrypt = { version = "0.9", optional = true } +rust-argon2 = { version = "0.8.2", optional = true } crc32fast = { version = "1.2.1", optional = true } [[example]] diff --git a/src/user_management/mod.rs b/src/user_management/mod.rs index fbc8868..2e56a81 100644 --- a/src/user_management/mod.rs +++ b/src/user_management/mod.rs @@ -31,7 +31,7 @@ pub enum UserManagerError { DatabaseError(sled::Error), DatabaseTransactionError(sled::transaction::TransactionError), DeserializeError(bincode::Error), - BcryptError(bcrypt::BcryptError), + Argon2Error(argon2::Error), } impl From for UserManagerError { @@ -52,9 +52,9 @@ impl From for UserManagerError { } } -impl From for UserManagerError { - fn from(error: bcrypt::BcryptError) -> Self { - Self::BcryptError(error) +impl From for UserManagerError { + fn from(error: argon2::Error) -> Self { + Self::Argon2Error(error) } } @@ -64,7 +64,7 @@ impl std::error::Error for UserManagerError { Self::DatabaseError(e) => Some(e), Self::DatabaseTransactionError(e) => Some(e), Self::DeserializeError(e) => Some(e), - Self::BcryptError(e) => Some(e), + Self::Argon2Error(e) => Some(e), _ => None } } @@ -83,8 +83,8 @@ impl std::fmt::Display for UserManagerError { write!(f, "Error accessing the user database: {}", e), Self::DeserializeError(e) => write!(f, "Recieved messy data from database, possible corruption: {}", e), - Self::BcryptError(e) => - write!(f, "Bcrypt Error, likely malformed password hash, possible database corruption: {}", e), + Self::Argon2Error(e) => + write!(f, "Argon2 Error, likely malformed password hash, possible database corruption: {}", e), } } } diff --git a/src/user_management/user.rs b/src/user_management/user.rs index 445b081..3abba2b 100644 --- a/src/user_management/user.rs +++ b/src/user_management/user.rs @@ -259,7 +259,7 @@ impl SignedInUser { try_password: impl AsRef<[u8]> ) -> Result { if let Some(hash) = &self.inner.pass_hash { - Ok(bcrypt::verify(try_password, hash.as_str())?) + Ok(argon2::verify_encoded(hash.as_str(), try_password.as_ref())?) } else { Err(super::UserManagerError::PasswordNotSet) }