Skip to main content

BetterAuthScrypt

Struct BetterAuthScrypt 

Source
pub struct BetterAuthScrypt;
Expand description

Better Auth’s password hashes, as @better-auth/utils/password writes them: "<salt>:<key>", where the salt is 16 random bytes in lowercase hex and the key is scrypt (N = 16384, r = 16, p = 1, 64 bytes) of the NFKC-normalized password, salted with the salt’s hex string as UTF-8 (not the 16 bytes it encodes), in lowercase hex.

New hashes are written in the same format and PasswordHasher::needs_rehash is always false, so a Better Auth app on the same database keeps verifying every password, and rolling back to it loses nobody.

Each hash takes BetterAuthScrypt::MEMORY_BYTES (32 MiB), against argon2id’s 19 MiB, so cap how many run at once with EmailPassword::max_concurrent_hashes; BetterAuthCompat does. It’s weaker than fastauth’s default argon2id: use it only while a Better Auth app shares the database.

Implementations§

Source§

impl BetterAuthScrypt

Source

pub const MEMORY_BYTES: usize

scrypt’s working memory per hash: 128 · N · r bytes, 32 MiB.

Source

pub fn hash_with_salt(password: &str, salt: &str) -> String

The hash of password with this salt. Better Auth’s salts are 32 lowercase hex characters; PasswordHasher::hash makes a random one.

Trait Implementations§

Source§

impl Clone for BetterAuthScrypt

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 BetterAuthScrypt

Source§

impl Debug for BetterAuthScrypt

Source§

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

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

impl Default for BetterAuthScrypt

Source§

fn default() -> Self

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

impl PasswordHasher for BetterAuthScrypt

Source§

fn verify(&self, password: &str, hash: &str) -> Result<bool, String>

Like Better Auth: the first two :-separated parts are the salt and the key, and the key must equal the lowercase hex of the derived key. A hash without both parts is an error, as it is in Better Auth.

Source§

fn hash(&self, password: &str) -> Result<String, String>

Source§

fn needs_rehash(&self, hash: &str) -> bool

Whether a stored hash should be replaced on the next successful sign-in.

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<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> 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> 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<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