Bcrypt とは?
「 blowfish 」という暗号アルゴリズムを用いたパスワードハッシュ関数です。
インストール
npm install bcrypt
「 blowfish 」という暗号アルゴリズムを用いたパスワードハッシュ関数です。
npm install bcrypt
const bcrypt = require('bcrypt');
const saltRounds = 10;
const passwrod = "password";
let salt = bcrypt.genSaltSync(saltRounds); // ソルトの生成
console.log(salt);
let hash = bcrypt.hashSync(passwrod, salt); // ハッシュの生成
console.log(hash);
console.log(bcrypt.compareSync("password", hash)); // true ハッシュの照合
const bcrypt = require('bcrypt');
const saltRounds = 10;
const passwrod = "password";
let salt = bcrypt.genSaltSync(saltRounds);
let hash = bcrypt.hashSync(passwrod, salt);
console.log(bcrypt.compareSync("password", hash));
const bcrypt = require('bcrypt');
const saltRounds = 10;
const password = 'password';
console.log('start');
console.time('A');
bcrypt.hash(password, saltRounds)
.then(hash => {
console.log(hash);
console.timeEnd('A');
})
.catch(error => {
console.log(error);
});
console.log('end');
const bcrypt = require('bcrypt');
const hash = '$2b$10$DtZ8RoPTSXZcH8J8pYprwORQ2ZGsNbW1bbD8oYafHpMf7leiDKnri';
const password = 'password';
console.log('start');
console.time('A');
bcrypt.compare(password, hash)
.then(res => {
console.log(res);
console.timeEnd('A');
})
.catch(error => {
console.log(error);
});
console.log('end');