ktvmanager/lib/passwordEncrypt.js

18 lines
498 B
JavaScript
Raw Normal View History

2021-02-16 13:58:46 +00:00
const bcrypt = require('bcrypt');
const saltRounds = 10;
const myPlaintextPassword = 's0/\/\P4$$w0rD';
const someOtherPlaintextPassword = 'not_bacon';
function hashPassword() {
const hash = bcrypt.hashSync(myPlaintextPassword, saltRounds);
return hash
}
async function checkPassword(h) {
let t = bcrypt.compareSync(myPlaintextPassword, h); // true
let b = bcrypt.compareSync(someOtherPlaintextPassword, h); // false
console.log(t, b)
}
let a = hashPassword()
checkPassword(a)