This is how I verify the bcrypt passwords in NodeJS that were created in Python Flask with bcrypt. Hope that helps.
const { pbkdf2Sync } = require('node:crypto');
function validatePassword(password, passwordHash) {
// example: pbkdf2:sha256:150000$weUYb4Vf$cf99f5c4b956b9af7fae3a2ff8d8ba921fd7967a1e001f2af2fdc39754f8fecd
const code2 = passwordHash.split('$');
// [0]pbkdf2:sha256:150000,
// [1]weUYb4Vf
// [2]cf99f5c4b956b9af7fae3a2ff8d8ba921fd7967a1e001f2af2fdc39754f8fecd
const code1 = code2[0].split(':');
// [0]pbkdf2
// [1]sha256
// [2]150000
const salt = code2[1];
const iterations = parseInt(code1[2], 10);
const keyLen = 32;
const digest = code1[1];
const value = code2[2];
const derivedKey = pbkdf2Sync(
password,
salt,
iterations,
keyLen,
digest
).toString('hex');
return value === derivedKey;
}
This is how I generate the Flask Login bcrypt hashes.
const { pbkdf2Sync } = require('node:crypto');
const randonstring = require('randomstring');
const password = <TYPE_YOUR_PASSWORD_HERE>;
const headerKey = 'pbkdf2:sha256:150000$';
const salt = randonstring.generate(8);
const iterations = parseInt(150000, 10);
const keyLen = 32;
const digest = 'sha256';
const derivedKey = pbkdf2Sync(
password,
salt,
iterations,
keyLen,
digest
).toString('hex');
const fullKey = headerKey + derivedKey;