pub struct PasswordEngine { /* private fields */ }Expand description
密码哈希执行器:Argon2 运算 + 受控并发上限。
Implementations§
Source§impl PasswordEngine
impl PasswordEngine
Sourcepub fn new(max_concurrency: usize) -> Result<Self, BaseError>
pub fn new(max_concurrency: usize) -> Result<Self, BaseError>
创建执行器;max_concurrency 为同时进行的 Argon2 运算上限,必须大于 0。
Sourcepub async fn hash(&self, password: &str) -> Result<String, BaseError>
pub async fn hash(&self, password: &str) -> Result<String, BaseError>
计算密码的 Argon2 哈希(PHC 字符串格式)。
Sourcepub async fn verify(
&self,
password: &str,
encoded: &str,
) -> Result<bool, BaseError>
pub async fn verify( &self, password: &str, encoded: &str, ) -> Result<bool, BaseError>
校验密码明文与已存储的 PHC 哈希是否匹配。
Sourcepub async fn verify_or_dummy(
&self,
password: &str,
encoded: Option<&str>,
) -> Result<bool, BaseError>
pub async fn verify_or_dummy( &self, password: &str, encoded: Option<&str>, ) -> Result<bool, BaseError>
等时校验:账号记录缺失时也对内置 dummy 哈希执行一次完整的 Argon2 校验。
认证入口(如登录)在「用户不存在」与「密码错误」之间必须保持一致的响应时间
与响应错误,否则时间差会泄露用户名是否存在(时序枚举旁路)。传入
Some(真实哈希) 时语义与 Self::verify 完全一致;传入 None 时走同一条
校验代码路径运算内置 dummy 哈希,并恒返回 Ok(false)——dummy 哈希
不对应任何真实账号,即使碰巧匹配也不能视为认证通过。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for PasswordEngine
impl !UnwindSafe for PasswordEngine
impl Forget for PasswordEngine
impl Freeze for PasswordEngine
impl Move for PasswordEngine
impl Send for PasswordEngine
impl Sync for PasswordEngine
impl Unpin for PasswordEngine
impl UnsafeUnpin for PasswordEngine
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