feat: hash password
This commit is contained in:
24
server/src/utils/auth.ts
Normal file
24
server/src/utils/auth.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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 }
|
||||
Reference in New Issue
Block a user