Putting It All Together
Learn how to generate hashes with salts in Node.js.
We'll cover the following
Coding our application
Now that we’ve covered the basics, let’s write a little code.
The scenario here is that we are registering a new user. We will need to generate a random salt, generate their password hash, then store those to an imaginary database for authentication in the future.
We’re going to use the bcrypt
module for our code here. This will simplify the process of handling passwords. Additionally, never create your own crypto. Cryptographic code should be thoroughly vetted by as many people as possible. Use well-respected open source modules with no known security issues.
Let’s get to it. To generate a salt and hash a users password, we do the following:
Get hands-on with 1400+ tech skills courses.