1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Password hashing port ([`IPasswordHasher`]).
//!
//! Applications hash and verify passwords through this port instead of carrying
//! their own Argon2 (or bcrypt, or scrypt) code. Hashes are **PHC strings** —
//! the self-describing `$argon2id$v=19$m=…,t=…,p=…$salt$hash` format — so the
//! algorithm and its parameters travel with the stored value and can be upgraded
//! without a schema change.
//!
//! The default implementation is `Argon2PasswordHasher` in `rust-webx-host`
//! (feature `password-argon2`, on by default); it runs Argon2 on a blocking
//! thread so a login does not stall the async runtime. Register a different
//! implementation in DI to replace it — handlers keep injecting
//! `Arc<dyn IPasswordHasher>` and never need to change.
use crateResult;
/// Hash and verify passwords (Argon2id by default).
///
/// ```ignore
/// let phc = hasher.hash(&password).await?; // login / registration
/// let ok = hasher.verify(&password, &stored.phc).await?; // 401 on false
/// if ok && hasher.needs_rehash(&stored.phc) {
/// stored.phc = hasher.hash(&password).await?; // transparent upgrade
/// }
/// ```