NODE.JS-如何使用bcrypt检查Laravel哈希密码? [英] NODE.JS - How to check a Laravel hashed password with bcrypt?
问题描述
我正在开发一个Node.js
应用程序,该应用程序需要使用来自Laravel
应用程序的相同数据库信息登录.
I'm developing a Node.js
application that needs to log in using the same database information from a Laravel
aplication.
我已经阅读了有关BCrypt
的内容,并试图将其与数据库中存储的Laravel
密码进行比较.
I've read about BCrypt
and trying to use it to make a comparison of the hashed password it generates with the Laravel
one stored in the database.
因此,根据BCrypt
的文档,我需要执行以下操作:
So, by the documentation of BCrypt
, I need to do something like that:
var salt = bcrypt.genSaltSync(saltRounds);
var hash = bcrypt.hashSync(myPlaintextPassword, salt);
但是我不知道如何使用与Laravel
完全相同的盐来哈希密码.我需要使用 APP_KEY 来做到这一点吗?
But I have no idead on how to use the exact same salt from Laravel
to hash my password. I need to use the APP_KEY to do this?
推荐答案
I fond the answer here. It's way easier than I thought.
var hash = '$2y$08$9TTThrthZhTOcoHELRjuN.3mJd2iKYIeNlV/CYJUWWRnDfRRw6fD2';
var bcrypt = require('bcrypt');
hash = hash.replace(/^\$2y(.+)$/i, '$2a$1');
bcrypt.compare("secret", hash, function(err, res) {
console.log(res);
});
这篇关于NODE.JS-如何使用bcrypt检查Laravel哈希密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!