Class: Hasher

Hasher


new Hasher()

Creates and validates hashes. By default, this class uses 30,000 iterations, Hexadecimal encoding scheme, SHA-512 hashing method, and generates a 512-byte key.

Source:

Members


<inner> saltByte :Number

Length of the salt in bytes

Type:
  • Number
Source:

Methods


generateSalt(callback [, urand])

Parameters:
Name Type Argument Default Description
callback Hasher~saltCallback

Handles the randomly generated salt

urand Boolean <optional>
true

Determines whether to use /dev/urandom or the time stamp as the random source

Source:

hash(pwd, callback [, urand])

Hashes the provided pass-phrase

Parameters:
Name Type Argument Default Description
pwd String

Password to hash

callback Hasher~hashCallback

Handles the hashed object

urand Boolean <optional>
true

Determines whether to use /dev/urandom or the time stamp as the random source

Source:

validate(new_, old, callback [, enc])


DEPRECATED since v2.2.0 in favor of Hasher#verify


Parameters:
Name Type Argument Description
new_ String

Given pass-phrase

old String

The encoded hash string to compare to

callback Hasher-validatorCallback

Handles the validation result

enc String <optional>

The encoding scheme to be used (uses hasher.encoding as default)

Source:
Example
// Create a hash
hasher.hash("password", (err, hashed) => {
    const old = hashed.toString(hasher.encoding); // Generate hash string with default encoding scheme
    hasher.validate("password", old, (valid) => {
        assert.equal(valid, true);
    });
});

verify(new_, old [, enc], callback)

Parameters:
Name Type Argument Description
new_ String

Given pass-phrase

old String

The encoded hash string to compare to

enc String <optional>

The encoding scheme to be used (uses hasher.encoding as default)

callback Hasher-verifierCallback

Handles the verification result

Source:
Example
// Create a hash
hasher.hash("password", (err, hashed) => {
  const old = hashed.toString(hasher.encoding); // Generate hash string with default encoding scheme
  hasher.verify("password", old, (err, valid) => {
    if (err) console.error(err);
    assert.equal(valid, true);
  });
});

Type Definitions


hashCallback(err, hashed)

This callback takes the generated hash as an Encoded object. It also handles any errors from the PBKDF2 process.

Parameters:
Name Type Description
err Object
hashed Encoded

The hashed object

Source:
See:

validatorCallback(valid)

This callback handles the validation result.

Parameters:
Name Type Description
valid Boolean

Validation test result

Deprecated:
  • since v2.2.0
Source:

verifierCallback(err, valid)

This callback handles the verification result.

Parameters:
Name Type Description
err Object
valid Boolean

verification test result

Source: