-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (24 loc) · 808 Bytes
/
index.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
import saltedSha256 from "salted-sha256";
const checkPassword = (password, dbPassword) => {
const getSaltFromPassword = (password) => {
const salt = password.split("$");
return salt[2];
};
const generateNewPassword = (salt, password) => {
const firstHash = saltedSha256(password);
const secondHash = saltedSha256(firstHash, salt);
const finalPassword = "$SHA$" + salt + "$" + secondHash;
return finalPassword;
};
const checkPassword = (givenPassword, dbPassword) => {
const saltFromPw = getSaltFromPassword(dbPassword);
const genNewPw = generateNewPassword(saltFromPw, givenPassword);
if (genNewPw === dbPassword) {
return true;
} else {
return false;
}
};
return checkPassword(password, dbPassword);
};
export default checkPassword;