2020-11-15 22:49:00 -06:00
|
|
|
const bcrypt = require('bcrypt');
|
|
|
|
|
require('../config/config');
|
|
|
|
|
|
|
|
|
|
const comparar = (password, dbPassword) => {
|
2022-01-03 17:20:34 -06:00
|
|
|
if (!bcrypt.compareSync(password, dbPassword)) return false;
|
2020-11-15 22:49:00 -06:00
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-03 17:20:34 -06:00
|
|
|
const encriptar = (password) =>
|
|
|
|
|
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
2020-11-15 22:49:00 -06:00
|
|
|
|
2020-11-22 20:36:55 -06:00
|
|
|
const generarPassword = () => {
|
2022-01-03 17:20:34 -06:00
|
|
|
const length = 8;
|
|
|
|
|
const charset =
|
2020-11-22 20:36:55 -06:00
|
|
|
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
|
|
|
let password = '';
|
|
|
|
|
|
|
|
|
|
for (let i = 0, n = charset.length; i < length; ++i)
|
|
|
|
|
password += charset.charAt(Math.floor(Math.random() * n));
|
|
|
|
|
return password;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = { comparar, encriptar, generarPassword };
|