swapped if for entry

This commit is contained in:
telastrus 2019-08-08 21:28:25 -04:00
parent eadf3a7671
commit 79b5c177cd

View File

@ -13,19 +13,20 @@ impl AuthProvider {
}
pub fn query(&mut self, username: String, password: String) -> bool {
if let Some(pass) = self.accounts.get(&username) {
if pass != &password {
warn!(
"User '{}' attempted to log in with invalid password '{}'!",
username, password
);
return false;
}
let pwd = password.clone();
if self.accounts.entry(username.clone()).or_insert_with(|| {
info!("Registered new user '{}'", &username);
pwd
}) == &password
{
info!("User '{}' successfully authenticated", username);
true
} else {
info!("Registered new user '{}'", username);
self.accounts.insert(username, password);
warn!(
"User '{}' attempted to log in with invalid password '{}'!",
username, password
);
false
}
true
}
}