Member-only story

Encrypt your Passwords in NodeJS

Get your passwords ready to be safely stored in a database and verify them with NodeJS and Bcrypt

Rémy Villulles
2 min readApr 14, 2021
Photo by cottonbro from Pexels

If you are just getting started with Nodejs and user authentication, you might have wondered how to encrypt your user’s passwords!

There is a library that does it for you: Bcrypt!

How does it work?

Bcrypt made it super simple to encrypt and check passwords, with a couple of functions, you can generate a hashed password for your users and allow them to log in to your website!

Keep in mind that once the password is encrypted, you cannot decrypt it.

Encrypt a password

To encrypt a password, you are first going to have to generate a salt for the password. Once the salt is generated, you can use it to hash your password.

const passwordSalt = bcrypt.genSaltSync(10);
const hashedPassword = bcrypt.hashSync(password, passwordSalt);

--

--

Rémy Villulles
Rémy Villulles

Written by Rémy Villulles

Fullstack developer, I love learning new technologies and try to stay up to date with the newest features

No responses yet