Bcrypt is not supported in Reactjs
Asked Answered
D

2

9

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);

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 

What's the cause of the error, and how can the problem be resolved?

Deracinate answered 23/3, 2018 at 6:1 Comment(0)
K
16

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):

bcryptjs

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.

Kaseykasha answered 23/3, 2018 at 6:4 Comment(0)
F
-2

var bcrypt = require('bcryptjs');

Footton answered 3/5, 2023 at 0:11 Comment(2)
please avoid code only answers, instead you want to format your code and give an explanationTwo
what makes you think they're not actually using npmjs.com/package/bcrypt? And what on earth does this add on top of the existing answer? Did you mean to suggest an edit to that answer?Savadove

© 2022 - 2024 — McMap. All rights reserved.