Skip to main content

PasswordAuth

Struct PasswordAuth 

Source
pub struct PasswordAuth;
Expand description

Shipped default authenticator: Argon2id verification against AdminUser.

An unknown email costs the same work as a wrong password, and every failure shows the same message. It stores an email trimmed and lowercased and looks it up the same way, so Ada@Example.com and ada@example.com are one account; a resource that edits an admin’s email stores it the same way. A row stored with capitals cannot sign in or reset its password: list the accounts that differ only in case with SELECT LOWER(TRIM(email)) FROM admin_users GROUP BY 1 HAVING COUNT(*) > 1, merge or delete them, then run UPDATE admin_users SET email = LOWER(TRIM(email)). SQLite’s LOWER folds ASCII letters only, so lowercase any other capital by hand.

Trait Implementations§

Source§

impl Authenticator for PasswordAuth

Source§

type User = AdminUser

The app’s user type.
Source§

async fn verify( &self, cx: &Cx, login: &str, password: &str, ) -> Result<Option<AdminUser>>

Verify login/password, returning the user on success. Read more
Source§

async fn find_by_id(&self, cx: &Cx, id: &str) -> Result<Option<AdminUser>>

Load the session’s user by PanelUser::user_id, with everything the request reads from it — its tenants included. Read more
Source§

fn confirm_password( &self, cx: &Cx, user: &Self::User, password: &str, ) -> impl Future<Output = Result<bool>> + Send

Whether password is user’s current password: what a page asks before a change a stolen session must not make, such as turning two-factor sign-in on. Read more
Source§

fn store_locale( &self, cx: &Cx, user: &Self::User, locale: &Locale, ) -> impl Future<Output = Result<()>> + Send

Stores locale as user’s after they pick it from the shell’s language menu, so their locale reads it on the next request, in another browser, and in the mail a job sends them. It runs only when the pick differs from that locale, and never while someone impersonates the user. Read more
Source§

impl Clone for PasswordAuth

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PasswordAuth

Source§

impl Debug for PasswordAuth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PasswordAuth

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EmailVerifier for PasswordAuth

Verifies an AdminUser’s address, storing the one the link proved. Install it with Auth::email_verification.

Source§

type User = AdminUser

The account a link verifies: the type the panel’s Authenticator loads, which mounting checks.
Source§

fn is_verified(&self, admin: &AdminUser) -> bool

Whether user proved it reads the address PanelUser::email answers. A user who has not reaches only the page that asks for the proof.
Source§

async fn store_verified_email( &self, _cx: &Cx, user_id: &str, email: &str, ex: &mut dyn Executor, ) -> Result<()>

Record, through the transaction ex, which commits when it returns Ok, that the account PanelUser::user_id user_id names proved it reads email: store email as the address it signs in with, which an email change makes new, and mark it verified. An id that names no account is an error, not a success: the link is spent either way. It may run again for one link when the database aborts the transaction for a concurrent one, so it writes only through ex.
Source§

impl PasswordResetter for PasswordAuth

Resets an AdminUser’s password, mailing the link to the email the account stores. Install it with Auth::password_reset.

Source§

type User = AdminUser

The account a reset names: the type the panel’s Authenticator loads, which mounting checks.
Source§

async fn find_by_email(&self, cx: &Cx, email: &str) -> Result<Option<AdminUser>>

The account email signs in as, or None. The address arrives trimmed, as the visitor typed it.
Source§

async fn reset_password( &self, _cx: &Cx, user_id: &str, password: &str, ex: &mut dyn Executor, ) -> Result<()>

Set the password of the account PanelUser::user_id user_id names to password, through the reset’s transaction ex, which commits when it returns Ok. The panel’s authenticator still loads the account and it may enter the panel; the password is at least MIN_PASSWORD_CHARS long and was typed twice. It may run again for one reset when the database aborts the transaction for a concurrent one, so it writes only through ex.
Source§

impl ProfileEditor for PasswordAuth

Edits the signed-in AdminUser’s name, email and password through a Profile. Changing the email or the password asks for the current password, and refuses a new password new_password_errors refuses and, once the current password verifies, an email another account holds. A changed password is a ProfileUpdate::Credentials. A new email goes through request_email_change: on a panel with Auth::email_verification it waits for its link, elsewhere it is stored at once, as a credential change. Install it with Auth::profile.

Source§

type Input = Profile

What the profile page asks for: Profile, or the app’s own #[derive(FormInput)] struct.
Source§

type User = AdminUser

The account the page edits: the type the panel’s Authenticator loads, which mounting checks.
Source§

fn fill(&self, _cx: &Cx, admin: &AdminUser) -> Profile

The form as the page first shows it, from the signed-in user. The page renders what FormInput::write writes, so an input that never writes its passwords shows them empty.
Source§

async fn validate( &self, _cx: &Cx, admin: &AdminUser, profile: &Profile, ex: &mut dyn Executor, ) -> Result<FieldErrors>

Refuse a submission save should not receive, such as a wrong current password: each error names an input field’s key and renders under its control. Defaults to none. A key no control renders is a declaration error: the page would show no message. Read more
Source§

async fn save( &self, cx: &Cx, admin: &AdminUser, profile: Profile, ex: &mut dyn Executor, ) -> Result<ProfileUpdate>

Write a validated input to user’s account through the transaction ex, which commits when it returns Ok, and say whether a credential changed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more