Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bcrypt is not supported in Reactjs

Tags:

reactjs

bcrypt

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 

Can you help me? Thank you

like image 349
jayanes Avatar asked Dec 23 '22 08:12

jayanes


1 Answers

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.

like image 124
J Livengood Avatar answered Jan 14 '23 10:01

J Livengood