Added a bunch of logging to user management

devel
Emi Tatsuo 2 years ago
parent ac9650977b
commit 33114616e0
Signed by: Emi
GPG Key ID: 68FAB2E2E6DFC98B

@ -152,7 +152,7 @@ impl NotSignedInUser {
)?;
Ok(id)
})?;
info!("User {}#{:08x} registered!", partial.username, id);
info!("User {}#{:08X} registered!", partial.username, id);
Ok(RegisteredUser::new(
id,
@ -203,7 +203,6 @@ impl NotSignedInUser {
}
}
info!("User {} attached certificate with fingerprint {:x?}", username, &self.certificate[..]);
user.add_certificate(self.certificate)?;
user.active_certificate = Some(self.certificate);
Ok(Some(user))
@ -295,13 +294,18 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
try_password: impl AsRef<[u8]>
) -> Result<bool> {
if let Some((hash, salt)) = &self.inner.pass_hash {
Ok(argon2::verify_raw(
let result = argon2::verify_raw(
try_password.as_ref(),
salt,
hash.as_ref(),
&ARGON2_CONFIG,
)?)
)?;
if !result {
info!("Someone failed to log in to the account of {} (wrong)", self);
}
Ok(result)
} else {
info!("Someone failed to log in to the account of {} (not set)", self);
Err(super::UserManagerError::PasswordNotSet)
}
}
@ -350,6 +354,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
salt,
));
self.has_changed = true;
info!("Updated password for user {}", self);
Ok(())
}
@ -363,6 +369,7 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
{
self.inner.store(&self.manager.users, self.uid)?;
self.has_changed = false;
debug!("Changes to user {} saved", self);
Ok(())
}
@ -394,6 +401,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
Ok(())
})?;
info!("User {} added certificate with fingerprint {:X?}", self, certificate);
Ok(())
}
@ -436,6 +445,8 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
Ok(())
})?;
info!("Deleted user {}", self);
Ok(())
}
@ -469,6 +480,19 @@ impl<UserData: Serialize + DeserializeOwned> RegisteredUser<UserData> {
}
}
impl <UD: Serialize + DeserializeOwned> std::fmt::Display for RegisteredUser<UD> {
/// Synthesize a unique identifier for the user including their username
///
/// This is literally just the user's username postfixed with `#` and eight characters
/// representing the hex encoding of the users id. This is not guaranteed not to
/// change, but is great for logging, because it is simultaniously human-readable but
/// at the same time the last 8 characters offer a way to look up a user even with
/// username changes
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}#{:08X}", self.username(), self.uid)
}
}
impl<UserData: Serialize + DeserializeOwned> std::ops::Drop for RegisteredUser<UserData> {
fn drop(&mut self) {
if self.has_changed {
@ -491,6 +515,7 @@ impl<UserData: Serialize + DeserializeOwned> AsMut<UserData> for RegisteredUser<
}
}
#[cfg(all(feature = "user_management_advanced", not(feature = "ring")))]
/// Inexpensive but low quality random
fn pcg8(state: &mut u16) -> u8 {

Loading…
Cancel
Save