OxL Reference

data password

Password hashing with scrypt (N = 2^15, r = 8, p = 1 by default). The result is one text, $scrypt$ln=15,r=8,p=1$<salt>$<hash> (base64, no padding), that carries everything verify needs.

Example:

oxl✓ checked in CI
use std.crypto { password }

fn main() io, rand {
  let stored = password.hash("correct horse")
  print("{password.verify("correct horse", stored)} {password.verify("wrong", stored)}")
}
Output
true false
pub(api) data password

Thread safety. pure functions apart from the random salt; safe from any task.

Since. 1.0.0-beta

Methods

hash(pw: str) -> str rand
Hashes a password with scrypt; the result carries the salt and the cost, so verify needs only the text.
hashWith(pw: str, logN: i64) -> str rand
logN is the base-2 logarithm of the scrypt cost N (memory is 128 N 8 bytes); 10 is for tests only.
verify(pw: str, encoded: str) -> bool
Checks pw against a text made by hash; a malformed text is simply false.

Defined in: std/crypto/crypto.oxl:769

See also