UNPKG

@foal/core

Version:

Full-featured Node.js framework, with no complexity

20 lines (19 loc) 952 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyPassword = verifyPassword; const crypto_1 = require("crypto"); const util_1 = require("util"); const utils_1 = require("./utils"); /** * Compare a plain text password and a hash to see if they match. * * @export * @param {string} plainTextPassword - The password in clear text. * @param {string} passwordHash - The password hash generated by the `hashPassword` function. * @returns {Promise<boolean>} True if the hash and the password match. False otherwise. */ async function verifyPassword(plainTextPassword, passwordHash) { const { digestAlgorithm, iterations, salt, derivedKey, keyLength } = (0, utils_1.decomposePbkdf2PasswordHash)(passwordHash); const password = await (0, util_1.promisify)(crypto_1.pbkdf2)(plainTextPassword, salt, iterations, keyLength, digestAlgorithm); return (0, crypto_1.timingSafeEqual)(password, derivedKey); }