2024-09-23 23:44:21 +05:30
|
|
|
import bcrypt from "bcrypt";
|
|
|
|
|
|
2024-09-25 18:43:09 +05:30
|
|
|
export const hashPassword = (password: string) => {
|
2024-09-23 23:44:21 +05:30
|
|
|
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
|
2024-09-25 18:43:09 +05:30
|
|
|
export const comparePassword = (password: string, hash: any) => {
|
2024-09-23 23:44:21 +05:30
|
|
|
return bcrypt.compare(password, hash)
|
2024-09-23 23:53:35 +05:30
|
|
|
}
|