pub struct UserStore { /* private fields */ }Expand description
In-memory, serializable collection of users keyed by name.
Implementations§
Source§impl UserStore
impl UserStore
Sourcepub fn create_user(
&mut self,
name: &str,
password: &str,
role: &str,
) -> Result<(), AuthError>
pub fn create_user( &mut self, name: &str, password: &str, role: &str, ) -> Result<(), AuthError>
Create a new user.
Errors if name already exists or role is not a known builtin.
The password is hashed with argon2id before storage.
Sourcepub fn authenticate(&self, name: &str, candidate: &str) -> Option<&User>
pub fn authenticate(&self, name: &str, candidate: &str) -> Option<&User>
Authenticate a user by name + candidate password.
Returns Some(&User) only on a verified match. Unknown user or wrong
password both return None.
Sourcepub fn set_role(&mut self, name: &str, role: &str) -> Result<(), AuthError>
pub fn set_role(&mut self, name: &str, role: &str) -> Result<(), AuthError>
Reassign a user’s role.
Errors if the user is unknown or the role is not a known builtin.
Sourcepub fn set_password(
&mut self,
name: &str,
new_password: &str,
) -> Result<(), AuthError>
pub fn set_password( &mut self, name: &str, new_password: &str, ) -> Result<(), AuthError>
Replace a user’s password with a new argon2id hash, preserving role.
Errors if the user is unknown. The new plaintext is held in a buffer that is zeroed on drop.
Sourcepub fn delete_user(&mut self, name: &str) -> Result<(), AuthError>
pub fn delete_user(&mut self, name: &str) -> Result<(), AuthError>
Remove a user. Errors if the user is unknown.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the store has no users. When empty, the server falls back to the legacy shared-password authentication path.
Sourcepub fn list_users(&self) -> Vec<(String, String)>
pub fn list_users(&self) -> Vec<(String, String)>
List users as (name, role) pairs. Never exposes password hashes.