pub struct Safe(/* private fields */);Expand description
Interface to the password database.
Implementations§
Source§impl Safe
impl Safe
Sourcepub async fn new(p: impl AsRef<Path>) -> Result<Self, Error>
pub async fn new(p: impl AsRef<Path>) -> Result<Self, Error>
Open an SQLite connection with specified database file and create a SafeBox.
Sourcepub fn issue_token(&self, user: &str) -> String
pub fn issue_token(&self, user: &str) -> String
Issue a token to the speficied user.
Sourcepub fn invalidate_token(&self, token: &str)
pub fn invalidate_token(&self, token: &str)
Invalidate a token.
§Example
use simple_safe::Safe;
let safe = Safe::new("password.db").await.unwrap();
let token = safe.issue_token("alice");
assert!(safe.verify_token(&token).unwrap() == "alice");
safe.invalidate_token(&token);
assert!(safe.verify_token(&token).is_none())Sourcepub fn invalidate_user_token(&self, user: &str)
pub fn invalidate_user_token(&self, user: &str)
Invalidate all tokens related to specified user.
Sourcepub fn expire_token(&self, duration: Duration)
pub fn expire_token(&self, duration: Duration)
Make all tokens older than duration expire.
Sourcepub async fn create(&self, user: &str, pass: &str) -> Result<(), Error>
pub async fn create(&self, user: &str, pass: &str) -> Result<(), Error>
Create new user entry with username and password.
Sourcepub async fn verify(&self, user: &str, pass: &str) -> Result<bool, Error>
pub async fn verify(&self, user: &str, pass: &str) -> Result<bool, Error>
Verify the provided username and password.
Return a new token if successful.
Sourcepub fn verify_token(&self, token: &str) -> Option<String>
pub fn verify_token(&self, token: &str) -> Option<String>
Verify the provided token.
Returns the user it belongs to if valid.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Safe
impl !RefUnwindSafe for Safe
impl Send for Safe
impl Sync for Safe
impl Unpin for Safe
impl !UnwindSafe for Safe
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more