Bcrypt
Password hashing using iterated HMAC-SHA256 with random salt.
Install
bash
wyn pkg install github.com/wynlang/bcryptUsage
wyn
// Hash a password
hashed = Bcrypt.hash("mypassword")
// Verify a password
if Bcrypt.verify("mypassword", hashed) {
print("correct")
}
// Two hashes of the same password differ (random salt)
h1 = Bcrypt.hash("secret")
h2 = Bcrypt.hash("secret")
// h1 != h2, but both verifyAPI
| Method | Description |
|---|---|
Bcrypt.hash(password: string) -> string | Hash with random salt, 10 rounds |
Bcrypt.verify(password: string, hash: string) -> bool | Verify password against hash |
Hash Format
$wyn$10$<32-char-hex-salt>$<64-char-hex-hash>
See Also
- Crypto - SHA-256 and HMAC for non-password hashing
- Web Framework - use bcrypt in web authentication
- Build a Web Server - HTTP server tutorial