Files
parcer/server/src/utils/auth.ts

24 lines
612 B
TypeScript
Raw Normal View History

2024-09-23 23:44:21 +05:30
import bcrypt from "bcrypt";
const hashPassword = (password) => {
return new Promise((resolve, reject) => {
bcrypt.genSalt(12, (err, salt) => {
if (err) {
reject(err)
}
bcrypt.hash(password, salt, (err, hash) => {
if (err) {
reject(err)
}
resolve(hash)
})
})
})
}
// password from frontend and hash from database
const comparePassword = (password, hash) => {
return bcrypt.compare(password, hash)
}
module.exports = { hashPassword, comparePassword }