refactoring part 1: camelcase naming, token vs pw naming

This commit is contained in:
2025-07-16 09:39:02 +02:00
parent b8e5031669
commit 34d5034a71
9 changed files with 96 additions and 91 deletions

View File

@@ -19,18 +19,18 @@ export function decryptToken(token: string) {
}
export function authenticate(user, pass) {
let token;
let JWTToken;
// hash user password
let hashed_pw = new jsSHA('SHA-512', 'TEXT').update(pass).getHash('HEX');
let hashedPW = new jsSHA('SHA-512', 'TEXT').update(pass).getHash('HEX');
let get_usr_stmt = 'SELECT name, pw FROM users WHERE name = ?';
const row = db.prepare(get_usr_stmt).get(user);
let stored_pw = row.pw;
let getUserSQLStmt = 'SELECT name, pw FROM users WHERE name = ?';
const row = db.prepare(getUserSQLStmt).get(user);
let storedPW = row.pw;
if (hashed_pw && hashed_pw === stored_pw) {
token = createToken({ id: user, admin: true });
if (hashedPW && hashedPW === storedPW) {
JWTToken = createToken({ id: user, admin: true });
}
return token;
return JWTToken;
}