@foal/core
Version:
Full-featured Node.js framework, with no complexity
50 lines (49 loc) • 1.85 kB
TypeScript
export declare const PASSWORD_ITERATIONS = 600000;
/**
* Options for password verification.
*
* @export
*/
export interface VerifyPasswordOptions {
/**
* Callback function called with a new hash when the password security needs to be upgraded.
*/
onPasswordUpgrade?: (newHash: string) => Promise<void> | void;
}
/**
* Service for password hashing and verification.
*
* @export
*/
export declare class PasswordService {
/**
* Hash a password using the PBKDF2 algorithm.
*
* Configured to use PBKDF2 + HMAC + SHA256.
* The result is a 64 byte binary string.
*
* The random salt is 16 bytes long.
* The number of iterations is 600,000.
* The length key is 32 bytes long.
*
* @param {string} plainTextPassword - The password to hash.
* @returns {Promise<string>} The derived key with the algorithm name, the number of iterations and the salt.
*/
hashPassword(plainTextPassword: string): Promise<string>;
/**
* Compare a plain text password and a hash to see if they match.
*
* @param {string} plainTextPassword - The password in clear text.
* @param {string} passwordHash - The password hash generated by the `hashPassword` method.
* @param {VerifyPasswordOptions} [options] - Optional configuration object.
* @returns {Promise<boolean>} True if the hash and the password match. False otherwise.
*/
verifyPassword(plainTextPassword: string, passwordHash: string, options?: VerifyPasswordOptions): Promise<boolean>;
/**
* Check if a password hash needs to be refreshed.
*
* @param {string} passwordHash - The password hash to check.
* @returns {boolean} True if the password hash needs to be refreshed. False otherwise.
*/
passwordHashNeedsToBeRefreshed(passwordHash: string): boolean;
}