-
Notifications
You must be signed in to change notification settings - Fork 4
/
hashFunctions.js
48 lines (44 loc) · 1.18 KB
/
hashFunctions.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
36
37
38
39
40
41
42
43
44
45
46
47
48
const bcrypt = require("bcryptjs");
const { promisify } = require("util");
const genSalt = promisify(bcrypt.genSalt);
const hash = promisify(bcrypt.hash);
const compare = promisify(bcrypt.compare);
module.exports.hashPass = password => {
return genSalt().then(salt => {
return hash(password, salt);
});
};
module.exports.checkPass = (password, hash) => {
return compare(password, hash);
};
module.exports.passRestrictions = password => {
if (password.length < 8) {
return false;
} else {
let upper = 0;
let lower = 0;
let num = 0;
for (let i = 0; i < password.length; i++) {
if (
password[i] == password[i].toUpperCase() &&
isNaN(password[i])
) {
upper += 1;
}
if (
password[i] == password[i].toLowerCase() &&
isNaN(password[i])
) {
lower += 1;
}
if (!isNaN(password[i])) {
num += 1;
}
}
if (upper > 0 && lower > 0 && num > 0) {
return true;
} else {
return false;
}
}
};