A simple solution is to use these function :
For typescript
import * as bcrypt from 'bcrypt';
const cryptPassword = (plaintextPassword: string) => {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(plaintextPassword, salt);
}
const comparePassword = (plaintextPassword: string, hashword: string) => {
return bcrypt.compareSync(plaintextPassword, hashword);
}
export {
cryptPassword,
comparePassword
};
Using js
var bcrypt = require('bcrypt');
const cryptPassword = (plaintextPassword) => {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(plaintextPassword, salt);
}
const comparePassword = (plaintextPassword, hashword) => {
return bcrypt.compareSync(plaintextPassword, hashword);
}
export {
cryptPassword,
comparePassword
};