-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathauth.js
35 lines (29 loc) · 815 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const bcrypt = require('bcrypt');
const fs = require('fs');
const https = require('https');
const SALT_ROUNDS = 10;
const passwordHash = async (password) => {
if (!password || typeof password !== 'string') {
throw new Error('Invalid password provided');
}
try {
const salt = await bcrypt.genSalt(SALT_ROUNDS);
return await bcrypt.hash(password, salt);
} catch (err) {
throw new Error('Error hashing password: ' + err.message);
}
};
const passwordCheck = async (password, hashP) => {
if (!password || !hashP) {
throw new Error('Password and hash must be provided');
}
try {
return await bcrypt.compare(password, hashP);
} catch (err) {
throw new Error('Error comparing passwords: ' + err.message);
}
};
module.exports = {
passwordHash,
passwordCheck,
};