bcrypt

1061 ワード

npm view bcrypt
https://github.com/kelektiv/node.bcrypt.js#readme

  • npm install bcrypt

  • const bcrypt = require('bcrypt');	// import 하고
    const saltRounds = 10;			// 얼마나 많은 길이의 salt를 사용할 지 설정
    const myPlaintextPassword = 's0/\/\P4$$w0rD';
    const someOtherPlaintextPassword = 'not_bacon';
    bcrypt.genSalt(saltRounds, function(err, salt) {	// salt를 만들고 hash
        bcrypt.hash(myPlaintextPassword, salt, function(err, hash) {
            // Store hash in your password DB.
        });
    });
  • 比較APIを使用した比較パスワード
  • // Load hash from your password DB.
    bcrypt.compare(myPlaintextPassword, hash, function(err, result) {
        // result == true
    });
    bcrypt.compare(someOtherPlaintextPassword, hash, function(err, result) {
        // result == false
    });