NODE.JS-如何使用bcrypt检查Laravel哈希密码? [英] NODE.JS - How to check a Laravel hashed password with bcrypt?

查看:141
本文介绍了NODE.JS-如何使用bcrypt检查Laravel哈希密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆