Skip to content

Hash Class

The Hash class provides secure password hashing with Argon2, bcrypt, and scrypt.

hash = new Hash

hash.argon2(cPassword)

Hash a password using Argon2id. Returns a PHC-formatted hash string.

hashed = hash.argon2("mypassword")

hash.verifyArgon2(cPassword, cHash)

Verify a password against an Argon2 hash. Returns 1 if valid, 0 otherwise.

if hash.verifyArgon2("mypassword", storedHash)
    # Password correct
ok

hash.bcrypt(cPassword)

Hash a password using bcrypt.

hashed = hash.bcrypt("mypassword")

hash.verifyBcrypt(cPassword, cHash)

Verify a password against a bcrypt hash.

if hash.verifyBcrypt("mypassword", storedHash)
    # Password correct
ok

hash.scrypt(cPassword)

Hash a password using scrypt.

hashed = hash.scrypt("mypassword")

hash.verifyScrypt(cPassword, cHash)

Verify a password against a scrypt hash.

if hash.verifyScrypt("mypassword", storedHash)
    # Password correct
ok