in
Clone
https://git.tahinli.com/Tahinli/in.git
0 watching0 forksRustAGPL-3.0528.7 KiB9215377Tahinli27 days ago37 commits
| 1 | //! Password hashing with argon2id. Used for account passwords and for share-link passwords. The |
| 2 | //! blocking versions are slow by design, so async callers use the `_async` functions, which run them |
| 3 | //! on tokio's blocking pool. |
| 4 | |
| 5 | use PasswordHash; |
| 6 | use ; |
| 7 | use ; |
| 8 | |
| 9 | use crate; |
| 10 | |
| 11 | /// Memory cost of a hash, in KiB (19 MiB), time cost and lanes. They are written out here, not left to the |
| 12 | /// crate's defaults, so a crate upgrade cannot change new hashes silently. A stored hash carries its own |
| 13 | /// parameters, so every hash made before still verifies. |
| 14 | const M_COST_KIB: u32 = 19 * 1024; |
| 15 | const T_COST: u32 = 2; |
| 16 | const P_COST: u32 = 1; |
| 17 | |
| 18 | /// The argon2id hasher with the pinned parameters. |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | /// Hashes `pw` with argon2id (pinned parameters) and a random salt. Returns a PHC string. |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// Returns true only if `pw` matches the PHC string `hash`. A malformed hash also gives false, so |
| 35 | /// callers never have to tell "bad hash" apart from "wrong password". |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | /// [`hash_password`] on the blocking pool, so the async runtime is not held for the hashing time. |
| 44 | pub async |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | /// [`verify_password`] on the blocking pool. |
| 51 | pub async |
| 52 | |
| 53 | |
| 54 | |
| 55 |