Openwall PHPass class port to Node - Wordpress class used to hash passwords.
npm install @coxato/node-phpass/wp-includes/class-phpass.php class used to hash passwords.
npm install node-phpass old librariesnpm install @coxato/node-phpass new one, libraries updated
js
const PasswordHash = require('@coxato/node-phpass').PasswordHash;
const CRYPT_BLOWFISH = require('@coxato/node-phpass').CRYPT_BLOWFISH;
const CRYPT_EXT_DES = require('@coxato/node-phpass').CRYPT_EXT_DES;
// or
// const { PasswordHash, CRYPT_BLOWFISH, CRYPT_EXT_DES } = require('node-phpass')
const len = 8;
const portable = true;
// major PHP version, 5 or 7, as it is a port of PHPass PHP class we rely
// on php version on gensalt_private() method, it is an optional constructor
// argument which defaults to 7
const phpversion = 7;
const hasher = new PasswordHash(len, portable, phpversion);
console.log('Hashing 123456 string');
hasher.HashPassword('123456').then(hash => console.log('Private hash: ', hash));
hasher.HashPassword('123456', CRYPT_BLOWFISH).then(hash => console.log('BCrypt hash: ', hash));
hasher.HashPassword('123456', CRYPT_EXT_DES).then(hash => console.log('DES hash: ', hash));
`
Verify a hash
`js
const PasswordHash = require('@coxato/node-phpass').PasswordHash;
// or
// const { PasswordHash } = require('node-phpass')
const len = 8;
const portable = true;
// major PHP version, 5 or 7, as it is a port of PHPass PHP class we rely
// on php version on gensalt_private() method, it is an optional constructor
// argument which defaults to 7
const phpversion = 7;
const hasher = new PasswordHash(len, portable, phpversion);
const storedhash = '$P$BVaXtDXwf/ceSVp8VpLKx8bS2Y4O5F/';
const storedhash2 = '$P$BVaXtDXwf/ceSVp8VpLKx8bS2Y4O5E/';
const password = '123456';
const valid = hasher.CheckPassword(password, storedhash);
const invalid = hasher.CheckPassword(password, storedhash2);
console.log(valid ? 'OK' : 'INVALID');
console.log(invalid ? 'OK' : 'INVALID');
``