pub struct Authenticator { /* private fields */ }Expand description
Issues and verifies credentials for one running server.
Implementations§
Source§impl Authenticator
impl Authenticator
pub fn new(secret: impl Into<Vec<u8>>, session_ttl_secs: u64) -> Self
Sourcepub fn hash_password(&self, plaintext: &str) -> Result<String, Error>
pub fn hash_password(&self, plaintext: &str) -> Result<String, Error>
Hash a plaintext password with argon2id (random salt).
Sourcepub fn verify_password(&self, plaintext: &str, hash: &str) -> bool
pub fn verify_password(&self, plaintext: &str, hash: &str) -> bool
Verify a plaintext password against a stored argon2 hash.
Sourcepub fn issue_token(&self, user_id: Uuid) -> Result<String, Error>
pub fn issue_token(&self, user_id: Uuid) -> Result<String, Error>
Mint a signed session JWT for a user id.
Sourcepub fn verify_token(&self, token: &str) -> Result<Uuid, Error>
pub fn verify_token(&self, token: &str) -> Result<Uuid, Error>
Verify a session JWT and recover the user id it was issued for.
Sourcepub fn generate_api_key(&self) -> (String, String)
pub fn generate_api_key(&self) -> (String, String)
Generate a new API key: (plaintext, sha256_hex). The plaintext is shown
to the user once; only the hash is stored.
Sourcepub fn hash_api_key(plaintext: &str) -> String
pub fn hash_api_key(plaintext: &str) -> String
Deterministic hash used to look an API key up. SHA-256 (not argon2) so a single indexed equality lookup resolves the key.
Trait Implementations§
Source§impl Clone for Authenticator
impl Clone for Authenticator
Source§fn clone(&self) -> Authenticator
fn clone(&self) -> Authenticator
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Authenticator
impl RefUnwindSafe for Authenticator
impl Send for Authenticator
impl Sync for Authenticator
impl Unpin for Authenticator
impl UnsafeUnpin for Authenticator
impl UnwindSafe for Authenticator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more