Skip to content

🔒Password Hashing Aidan Omwando

Aidan98 edited this page Apr 6, 2022 · 5 revisions

Password hashing

I chose password hashing because our app requires a login and register system in order to work correctly and securely. password hashing helps keep the passwords of individual users save.

What is password hashing

Hashing on it's own is a one-way function that scrambles data, it takes plain text (like a password or other classified data) and turns it into a completely different string of characters with a specific length; no matter the length of the password, the hash will always have the same character length.

Argon2

I chose Argon2 because Bcrypt had a build error and Bcrypt.js had a build that was failing, as a result my lecturer advised me to look for an alternative and the module that resembles Bcrypt the most is Argon2. Like Bcrypt Argon2 uses "Salt" which adds a few random characters, that are unknown, to your password, in addition they are run through a hashing function.

Code examples

Here I hash the password that is in the password with the hashLength of 10 characters. NOTE The salt is automatically applied.

const argon2 = require('argon2');

try {
  const hash = await argon2.hash("password", {hashLength: 10});
} catch (err) {
  //...
}

To verify a password that is stored in a database or array.

try {
  if (await argon2.verify("<big long hash>", "password")) {
    // password match
  } else {
    // password did not match
  }
} catch (err) {
  // internal failure
}

Sources