Three Tips for Seeing Yourself More Clearly

It is hard to have great ideas, goals, and ambitions only to recognize that you have habits and behaviors that make accomplishing those great ideas, goals, and ambitions really challenging. It is one…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




A quick way for hashing passwords using Bcrypt with Nodejs

Let’s see how we can use it in our Node.js application.

Before we use it, let’s first have a look at some terms.

The table illustrates the relation of salt value the hashed value

Salt Rounds: This is the cost factor that indicates the amount of time needed to calculate a single bcrypt hash. Higher the salt rounds, the more hashing rounds are done, hence the time and difficulty is increased while brute-forcing. For example, a cost factor of n means that the calculation will be done 2^n times.

So, there are two ways to hash a password:

Now if we want to compare the password entered by the user with the previously stored password hash, we can easily compare it.

Both the ways mentioned above can also be achieved with promises, these methods (hash & compare) will return a Promise when a callback is not defined.

Bcrypt also provides methods like genSaltSync, HashSync and CompareSync to perform synchronously. However, aysnc methods are preferred because of the fact that hashing done by bcyrpt is CPU intensive, so the sync methods will block event loop and our application will not serve any other request until the sync methods are completed executed.

Add a comment

Related posts:

Fetch is the simplest crypto wallet

Fetch is not only the easiest way to find the best prices and trade tokens with one-click, it’s also a powerful and simple to use wallet to manage, monitor and use your Ethereum and ERC20 tokens…

Alimento

A descoberta da vida, do nascimento, de cada nomenclatura que a gente recebe em vida: pai, mãe, avô, filha. A dor é do outro, mas o amor fica. O amor esta ali pra tudo o que for acontecer. E ele não…

Anticipation

Ever since the worldwide release of Avengers: Infinity War on April 27, 2018, I haven’t had the chance to go out and watch it.The suspense is killing me for I cannot sleep soundly at night, my eating…