bcypt npm


비밀번호 해싱을 도와주는 라이브러리. 예제코드:

  • encrypt
const bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
const someOtherPlaintextPassword = 'not_bacon';

// technique 1
bcrypt.genSalt(saltRounds, (err, salt) => {
    bcrypt.hash(myPlaintextPassword, salt, (err, hash) => {
        // Store hash in your password DB
    });
});

// technique 2
bcrypt.hash(myPlaintextPassword, saltRounds, (err, hash) => {
    // Store hash in your password DB
});
  • check
// Load `hash` from your password DB
bcrypt.compare("password", hash, (err, result) => {
    // result => true or false
});