问题描述
我尝试使用bcrypt转换表单输入密码值.像这样添加后,首先我安装了bcrypt(npm install bcrypt --save)
I try to convert the form input password value using bcrypt.First I installed bcrypt (npm install bcrypt --save) after I added like this
var bcrypt = require('bcrypt');
var hash = bcrypt.hashSync(values.newPassword, 10);
然后在cmd显示屏中显示这样的错误
Then in the cmd display so mush errors like this
ERROR in ./node_modules/forever-agent/index.js Module not found: Error: Can't resolve 'tls' in
你能帮我吗?谢谢
推荐答案
因此,普通的bcrypt与典型的库不同.它是用C ++编写的,并在您 npm install
时为您的计算机编译.因此,它在浏览器中不起作用(以及更多).但是,有一个纯JavaScript实现与IS浏览器兼容(并且通常是可移植的):
So the normal bcrypt isn't like a typical library. It's written in c++ and compiled for your machine when you npm install
it. It does not work in the browser because of that (and more). However, there is a pure javascript implementation that IS browser compatible (and portable in general):
npm install bcryptjs
请阅读其浏览器实施指南以指导设置.为了生成加密安全的随机数,他们需要做一些小事情.
Do read their browser implementation to guide through setup. They have a few small things needing to be done to generate the cryptographically safe random numbers.
这篇关于React.js不支持Bcrypt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!