feat: 🎸 Better naming for vars

This commit is contained in:
Jin 2025-03-25 23:53:49 +01:00
parent 1afccb4129
commit c2a6d517f0
2 changed files with 11 additions and 12 deletions

View File

@ -63,7 +63,7 @@ app.use(`/icon.png`, express.static(path.join(scriptDir, "public/icon.png")));
app.use(sessionParser); app.use(sessionParser);
app.use(favicon(`${scriptDir}/../images/app-icons/icon.ico`)); app.use(favicon(`${scriptDir}/../images/app-icons/icon.ico`));
// Check if TOTP is enabled and validate the secret // Check if TOTP is enabled and validate TOTP secret is set
totp.isTotpEnabled(); totp.isTotpEnabled();
if (openID.checkOpenIDRequirements()) if (openID.checkOpenIDRequirements())

View File

@ -1,5 +1,3 @@
"use strict";
import utils from "../services/utils.js"; import utils from "../services/utils.js";
import optionService from "../services/options.js"; import optionService from "../services/options.js";
import myScryptService from "../services/encryption/my_scrypt.js"; import myScryptService from "../services/encryption/my_scrypt.js";
@ -68,12 +66,12 @@ function setPassword(req: Request, res: Response) {
} }
function login(req: Request, res: Response) { function login(req: Request, res: Response) {
const guessedPassword = req.body.password; const submittedPassword = req.body.password;
const guessedTotp = req.body.token; const submittedTotp = req.body.token;
if (verifyPassword(guessedPassword)) { if (verifyPassword(submittedPassword)) {
if (totp.isTotpEnabled()) { if (totp.isTotpEnabled()) {
if (!verifyTOTP(guessedTotp)) { if (!verifyTOTP(submittedTotp)) {
sendLoginError(req, res); sendLoginError(req, res);
return; return;
} }
@ -99,18 +97,18 @@ function login(req: Request, res: Response) {
} }
} }
function verifyTOTP(guessedToken: string) { function verifyTOTP(submittedToken: string) {
if (totp.validateTOTP(guessedToken)) return true; if (totp.validateTOTP(submittedToken)) return true;
const recoveryCodeValidates = recoveryCodeService.verifyRecoveryCode(guessedToken); const recoveryCodeValidates = recoveryCodeService.verifyRecoveryCode(submittedToken);
return recoveryCodeValidates; return recoveryCodeValidates;
} }
function verifyPassword(guessedPassword: string) { function verifyPassword(submittedPassword: string) {
const hashed_password = utils.fromBase64(optionService.getOption("passwordVerificationHash")); const hashed_password = utils.fromBase64(optionService.getOption("passwordVerificationHash"));
const guess_hashed = myScryptService.getVerificationHash(guessedPassword); const guess_hashed = myScryptService.getVerificationHash(submittedPassword);
return guess_hashed.equals(hashed_password); return guess_hashed.equals(hashed_password);
} }
@ -127,6 +125,7 @@ function sendLoginError(req: Request, res: Response) {
failedAuth: true, failedAuth: true,
totpEnabled: optionService.getOption('totpEnabled') && totp.checkForTotSecret(), totpEnabled: optionService.getOption('totpEnabled') && totp.checkForTotSecret(),
assetPath: assetPath, assetPath: assetPath,
appPath: appPath,
}); });
} }