Skip to content

infinity.bcrypt

Provides bcrypt hashing and verifying functionality for strings.

Module: infinity.crypto

Functions:
infinity.loadModule('infinity.crypto');

let hash = infinity.bcrypt.hash("dataToHash", 10);
console.debug(hash);
//$2a$10$3.ywjLH6iKKThUQl1iWNu.udUXZChZIxqJaVfTVph1LJcKTLUFyFi

console.debug(infinity.bcrypt.verify("dataToHash", hash));
//true

Functions

hash()

Returns the bcrypt hash of the given string.

Signature:

hash( password: string, cost?: number ): string

Parameters:

  • password: string

    The string to serve as a password.

  • cost: number, optional

    The number of rounds to run.

Return type: string

Example:

infinity.loadModule('infinity.crypto');
let hash = infinity.bcrypt.hash(dataToHash, 10);

verify()

Returns whether the provided hash corresponds to the given string.

Signature:

verify( password: string, hash: string ): boolean

Parameters:

  • password: string

    The original string used for the creation of the hash for the function to return true.

  • hash: string

    The hash to be checked.

Return type: boolean

Example:

infinity.loadModule('infinity.crypto');
console.debug(infinity.bcrypt.verify(dataToVerify, hash));