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 callbackHasher~saltCallback Handles the randomly generated salt
urandBoolean <optional>
true Determines whether to use
/dev/urandomor the time stamp as the random source- Source:
-
hash(pwd, callback [, urand])
-
Hashes the provided pass-phrase
Parameters:
Name Type Argument Default Description pwdString Password to hash
callbackHasher~hashCallback Handles the hashed object
urandBoolean <optional>
true Determines whether to use
/dev/urandomor the time stamp as the random source- Source:
-
validate(new_, old, callback [, enc])
-
Parameters:
Name Type Argument Description new_String Given pass-phrase
oldString The encoded hash string to compare to
callbackHasher-validatorCallback Handles the validation result
encString <optional>
The encoding scheme to be used (uses
hasher.encodingas 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
oldString The encoded hash string to compare to
encString <optional>
The encoding scheme to be used (uses
hasher.encodingas default)callbackHasher-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 errObject hashedEncoded The hashed object
- Source:
- See:
-
validatorCallback(valid)
-
This callback handles the validation result.
Parameters:
Name Type Description validBoolean Validation test result
- Deprecated:
-
- since v2.2.0
- Source:
-
verifierCallback(err, valid)
-
This callback handles the verification result.
Parameters:
Name Type Description errObject validBoolean verification test result
- Source: