How to Verify Hashed Passwords in Node.js and MySQL

How to Verify Hashed Passwords in Node.js and MySQL

Store one way hashed passwords in MySQL database and verify it using Node.js

Store one way hashed passwords in MySQL database and verify it using Node.js

Image for post

How to Store Passwords in a Database

First, we will see how to store passwords in the database?. Then we will see how to verify the one-way hashed passwords. Don’t store the plain text in the password field. It is a dangerous one. It creates many problems. The developer, DB admin, etc., who had access to the database are able to see the user passwords and they can do some illegal activity if they want. This is the first problem. So don’t store the passwords as plain text.

Next, suppose if your database is compromised/hacked, then the hackers are able to see the user passwords, and they will misuse the user information if you are not storing the passwords in an encrypted format. If the password is in an encrypted format, then there is no need to worry about that. Why because decrypting one-way hashed passwords is a very hectic process.

Can we decrypt the one-way hashed passwords?.

Yes, We can.

However, to decrypt one password you need more time. It is a big debate about security. No need to argue here. Let’s continue the topic. We can secure the database in less time and ask our users to change the passwords. So the big problem is solved if you are using encrypted passwords.

The bcrypt algorithm is mostly used for the one-way hashing(encrypt) of passwords. In this tutorial, we are going to see how to generate one-way hashed passwords and verify them using NodeJS.

Install Bcrypt

Install the bcrypt library using the below command inside your nodejs project.

npm i bcryptjs

Generate One-Way Hashed Passwords

const bcrypt = require('bcryptjs');

const password_hash=bcrypt.hashSync('dummy', 10);


programming nodejs javascript

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Decoding Nodejs

The main goal of this blog is to explain the “Architecture of Nodejs” and to know how the Nodejs works behind the scenes. Generally, most of the server-side languages, like PHP, ASP.NET, Ruby, and including Nodejs follows multi-threaded architecture. That means for each client-side request initiates a new thread or even a new process.

Hire NodeJs Developer

Looking to build dynamic, extensively featured, and full-fledged web applications? **[Hire NodeJs Developer]( "Hire NodeJs Developer")** to create a real-time, faster, and scalable...

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

Learning JavaScript: Development Environments for JavaScript Programming

One of the nice things about learning JavaScript these days is that there is a plethora of choices for writing and running JavaScript code. In this article, I’m going to describe a few of these environments and show you the environment I’ll be using in this series of articles.

Learn JavaScript - Full Course for Beginners. DO NOT MISS!!!

In this video tutorial, we'll learn Learn JavaScript - Full Course for Beginners. This complete 134-part JavaScript tutorial for beginners will teach you everything you need to know to get started with the JavaScript programming language. DO NOT MISS!!!