Skip to content
FutureBlitz

    Install

    Import std.crypto.passwords

    Bcrypt

    std.crypto.passwords

    struct

    Public Struct Bcrypt

    bcrypt, OpenBSD's password hash, 2 to the cost rounds of Blowfish's key setup.

    Examples

    // A cost of 4 is quick, for an example; a real one is 12 or more.
    Local kept = Try Bcrypt.Hash("correct horse", 4)
    Expect(kept.StartsWith("$2b$04$"))
    Expect(Bcrypt.Verify("correct horse", kept))
    Expect(!Bcrypt.Verify("wrong horse", kept))

    std/crypto/passwords.fb, line 89

    • @PanicsAtCaller Public Static Method Hash(password: String, cost: Int = 12): String Throws ArgumentError static 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 when cost is outside 4 to 31.

    • Public Static Method Verify(password: String, hash: String): Bool static method #

      Whether password is 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.