diff --git a/src/user_management/user.rs b/src/user_management/user.rs index b21f635..9a1a4fe 100644 --- a/src/user_management/user.rs +++ b/src/user_management/user.rs @@ -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 RegisteredUser { try_password: impl AsRef<[u8]> ) -> Result { 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 RegisteredUser { salt, )); self.has_changed = true; + + info!("Updated password for user {}", self); Ok(()) } @@ -363,6 +369,7 @@ impl RegisteredUser { { self.inner.store(&self.manager.users, self.uid)?; self.has_changed = false; + debug!("Changes to user {} saved", self); Ok(()) } @@ -394,6 +401,8 @@ impl RegisteredUser { Ok(()) })?; + info!("User {} added certificate with fingerprint {:X?}", self, certificate); + Ok(()) } @@ -436,6 +445,8 @@ impl RegisteredUser { Ok(()) })?; + info!("Deleted user {}", self); + Ok(()) } @@ -469,6 +480,19 @@ impl RegisteredUser { } } +impl std::fmt::Display for RegisteredUser { + /// 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 std::ops::Drop for RegisteredUser { fn drop(&mut self) { if self.has_changed { @@ -491,6 +515,7 @@ impl AsMut for RegisteredUser< } } + #[cfg(all(feature = "user_management_advanced", not(feature = "ring")))] /// Inexpensive but low quality random fn pcg8(state: &mut u16) -> u8 {