2021-04-07 12:33:16 +02:00
|
|
|
const bcrypt = require("bcryptjs")
|
2021-04-14 15:13:48 +02:00
|
|
|
const env = require("./environment")
|
2021-04-19 12:34:07 +02:00
|
|
|
const { v4 } = require("uuid")
|
2021-04-07 12:33:16 +02:00
|
|
|
|
2021-04-14 15:13:48 +02:00
|
|
|
const SALT_ROUNDS = env.SALT_ROUNDS || 10
|
2021-04-07 12:33:16 +02:00
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
exports.hash = async data => {
|
2021-04-07 12:33:16 +02:00
|
|
|
const salt = await bcrypt.genSalt(SALT_ROUNDS)
|
|
|
|
return bcrypt.hash(data, salt)
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.compare = async (data, encrypted) => {
|
|
|
|
return bcrypt.compare(data, encrypted)
|
|
|
|
}
|
2021-04-19 12:34:07 +02:00
|
|
|
|
2021-05-03 09:31:09 +02:00
|
|
|
exports.newid = function () {
|
2021-04-19 12:34:07 +02:00
|
|
|
return v4().replace(/-/g, "")
|
|
|
|
}
|