Import std.crypto.passwords
std.crypto.passwords
Argon2id and Bcrypt, for keeping passwords: Hash picks a new random salt and the parameters, and gives a String that has them with the hash, which is what to keep; Verify tells whether a password is the one a kept hash was made from. Both are slow on purpose, so guessing is too. Argon2id, over Argon2's reference code, is the one to choose; Bcrypt, over Solar Designer's crypt_blowfish, is for the hashes other systems keep.
std/crypto/passwords.fb
Types
Argon2id
struct
Public Struct Argon2id
Argon2id (RFC 9106), a hash that takes memory as well as time.
std/crypto/passwords.fb, line 22
-
The PHC string of
password's hash, "$argon2id$v=19$m=19456,t=2,p=1$$", with a new 16-byte salt and OWASP's parameters: 19 MiB of memory, 2 passes, and 1 lane. -
@PanicsAtCaller Public Static Method Hash(password: String, memory: Int, iterations: Int, parallelism: Int): Stringstatic method #The same, with
memoryKiB,iterationspasses, andparallelismlanes. Panics unlessparallelismis from 1 to 16777215,memoryis at least 8 timesparallelism, anditerationsis 1 or more. -
Whether
passwordis the one hash, a PHC string from Hash, was made from. A hash that isn't an Argon2id PHC string is no password's. -
@PanicsAtCaller Public Static Method Derive(password: UInt8[], salt: UInt8[], memory: Int, iterations: Int, parallelism: Int, length: Int, secret: UInt8[] = [], associated: UInt8[] = []): UInt8[]static method #lengthbytes of key frompasswordandsalt, with those costs, and withsecret, a key that isn't kept with the hash, andassociateddata, which can both be empty. Panics as Hash does, or unlesssaltis 8 bytes or more andlength4 or more.
Bcrypt
struct
Public Struct Bcrypt
bcrypt, OpenBSD's password hash, 2 to the cost rounds of Blowfish's key setup.
std/crypto/passwords.fb, line 66
-
@PanicsAtCaller Public Static Method Hash(password: String, cost: Int = 12): String Throws ArgumentErrorstatic method #password's hash, "$2b$$", with a new 16-byte salt, and a cost from 4 to 31, 12 unless it's given. bcrypt reads only a password's first 72 bytes, and none past a NUL, so a longer one, or one with a NUL, would share its hash with others; it throws an ArgumentError instead. Panics whencostis outside 4 to 31. -
Whether
passwordis the one hash, of any of bcrypt's versions, $2a$, $2b$, or $2y$, was made from, reading its first 72 bytes, as bcrypt does. A password with a NUL, or a hash that isn't bcrypt's, is none, like crypt_blowfish's $2x$, which gives many passwords one hash.
Report an issue with this page or with FutureBlitz on GitHub.