Skip to content

Instantly share code, notes, and snippets.

@DjjimmyHD
Last active August 19, 2020 01:36
Show Gist options
  • Save DjjimmyHD/1f44ef1083cfda45698bfc73de84a788 to your computer and use it in GitHub Desktop.
Save DjjimmyHD/1f44ef1083cfda45698bfc73de84a788 to your computer and use it in GitHub Desktop.

Data Protection and Hashing

Helpful Resources

Code Example of Bcrypt


const bcrypt = require("bcrypt");
const saltRounds = 8;
const plainTextPassword1 = "DFGh5546*%^__90";

bcrypt
  .genSalt(8)
  .then(salt => {
    console.log(`Salt: ${salt}`);
    return bcrypt.hash('DFGh5546*%^__90', '$2b$08$GDaOC.xi.6tChS8B1IOXt.');
  })
  .then(hash => {
    console.log(`hash: ${hash}`);

    // Store hash in your password DB.
  })
  .catch(err => console.error(err.message));


const hash = "$2b$08$GDaOC.xi.6tChS8B1IOXt.aXlD0XyLAlDbLNzJUaQjWicqyedDpie";

bcrypt.compare(plainTextPassword1, hash).then(res => {
    console.log(res);
  })
  .catch(err => console.error(err.message));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment