IKHSAN
ENID Baca dalam Bahasa Indonesia

pixies

Public
Branch
master
Latest commit
9b0697f26 October 2026

password.js

Open raw
import * as config from '../controller/config.js';
import bcrypt from 'bcryptjs';
import { readPasswords } from '../util/passwordHeader.js';

export default (allowViewAccess) => async (req, res, next) => {
    if (process.env.PREVIEW_MODE === "true") return next();

    let passwordHash = await config.getValue("password");
    let passwordLevel = await config.getValue("passwordLevel");

    if (passwordHash === "none") {
        req.viewMode = false;
        return next();
    }

    if (readPasswords(req).some(candidate => bcrypt.compareSync(candidate, passwordHash))) {
        req.viewMode = false;
        return next();
    }

    if (passwordLevel === "read" && allowViewAccess) {
        req.viewMode = true;
        return next();
    }

    return res.status(401).json({message: "Please provide the correct password in the header"});
};
bytes
851
lines
27
Type
js
Latest commit
26 October 2026