2022-08-27 19:25:14 +02:00
|
|
|
import bcrypt from 'bcryptjs';
|
2021-06-14 09:02:01 +02:00
|
|
|
|
2021-06-26 21:59:03 +02:00
|
|
|
// https://www.npmjs.com/package/bcrypt
|
2022-08-27 19:25:14 +02:00
|
|
|
export async function hash(password) {
|
2021-06-26 21:59:03 +02:00
|
|
|
try {
|
2021-10-02 16:40:49 +02:00
|
|
|
// salt rounds https://www.npmjs.com/package/bcrypt#user-content-a-note-on-rounds
|
|
|
|
return await bcrypt.hash(password, 10);
|
2023-07-21 07:41:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
throw new Error('Error hashing the password');
|
2021-06-26 21:59:03 +02:00
|
|
|
}
|
2021-06-14 09:02:01 +02:00
|
|
|
}
|
|
|
|
|
2022-08-27 19:25:14 +02:00
|
|
|
export async function compare(password, hash) {
|
2021-06-26 21:59:03 +02:00
|
|
|
try {
|
|
|
|
return await bcrypt.compare(password, hash);
|
2023-07-21 07:41:47 +02:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
|
2021-06-26 21:59:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-06-14 09:02:01 +02:00
|
|
|
}
|