私の同僚は、アカウント情報を保存するデータベースを持っています。アカウントの SHA256 ハッシュ化されたパスワードとソルト値は、生のバイナリ データ (ブロブ) として列に保存されます。
パスワードは、これを使用して PHP でハッシュされます (true は生の出力を示します)。
hash("sha256", $salt . $password, true);
PHPからデータベースに保存されているのと同じハッシュ化されたパスワードを取得する必要があるNode.jsサーバーに認証を実装しようとしていますが、これは機能していないようです:
/**
* Validates a password sent by an end user by comparing it to the
* hashed password stored in the database. Uses the Node.js crypto library.
*
* @param password The password sent by the end user.
* @param dbPassword The hashed password stored in the database.
* @param dbSalt The encryption salt stored in the database.
*/
function validatePassword(password, dbPassword, dbSalt) {
// Should the dbSalt be a Buffer, hex, base64, or what?
var hmac = crypto.createHmac("SHA256", dbSalt);
var hashed = hmac.update(password).digest('base64');
console.log("Hashed user password: " + hashed);
console.log("Database password: " + dbPassword.toString('base64'));
return hashed === dbPassword;
}