Switched from bcrypt to argon

This commit is contained in:
Emi Tatsuo 2020-11-19 16:07:52 -05:00
parent ff5f294dae
commit fb205cd397
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B
3 changed files with 9 additions and 9 deletions

View File

@ -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]]

View File

@ -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<sled::Error> for UserManagerError {
@ -52,9 +52,9 @@ impl From<bincode::Error> for UserManagerError {
}
}
impl From<bcrypt::BcryptError> for UserManagerError {
fn from(error: bcrypt::BcryptError) -> Self {
Self::BcryptError(error)
impl From<argon2::Error> 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),
}
}
}

View File

@ -259,7 +259,7 @@ impl<UserData: Serialize + DeserializeOwned> SignedInUser<UserData> {
try_password: impl AsRef<[u8]>
) -> Result<bool> {
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)
}