"use strict";
exports.id = 5710;
exports.ids = [5710];
exports.modules = {

/***/ 987909:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.verifyPassword = void 0;
const password_hash_1 = __webpack_require__(782014);
Object.defineProperty(exports, "verifyPassword", ({ enumerable: true, get: function () { return password_hash_1.verify; } }));
// You can change the parameters at any time and no existing passwords
// or cookies should break.  This will only impact newly created
// passwords and cookies.  Old ones can be read just fine (with the old
// parameters).
const HASH_ALGORITHM = "sha512";
const HASH_ITERATIONS = 1000;
const HASH_SALT_LENGTH = 32;
function passwordHash(password) {
    // This blocks the server for around 5ms.
    // There are newer async libraries as explained at https://www.npmjs.com/package/password-hash
    // that do NOT block, which maybe we should be using instead....
    return (0, password_hash_1.generate)(password, {
        algorithm: HASH_ALGORITHM,
        saltLength: HASH_SALT_LENGTH,
        iterations: HASH_ITERATIONS,
    });
}
exports["default"] = passwordHash;
//# sourceMappingURL=password-hash.js.map

/***/ }),

/***/ 578772:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {


Object.defineProperty(exports, "__esModule", ({ value: true }));
const crypto_1 = __webpack_require__(706113);
// This function is private and burried inside the password-hash
// library.  To avoid having to fork/modify that library, we've just
// copied it here.  We need it for remember_me cookies.
function hash(algorithm, salt, iterations, password) {
    // there are cases where createHmac throws an error, because "salt" is undefined
    if (algorithm == null || salt == null) {
        throw new Error(`undefined arguments: algorithm='${algorithm}' salt='${salt}'`);
    }
    iterations = iterations || 1;
    if (!isFinite(iterations) || iterations > 10000) {
        // If somebody could make their own cookie, they might set the number of iterations
        // to be very large and hang the server.
        throw Error("number of iterations invalid or too large");
    }
    let hash = password;
    for (let i = 1, end = iterations, asc = 1 <= end; asc ? i <= end : i >= end; asc ? i++ : i--) {
        hash = (0, crypto_1.createHmac)(algorithm, salt).update(hash).digest("hex");
    }
    return algorithm + "$" + salt + "$" + iterations + "$" + hash;
}
exports["default"] = hash;
//# sourceMappingURL=hash.js.map

/***/ }),

/***/ 820540:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {


var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getRememberMeHash = exports.deleteAllRememberMe = exports.deleteRememberMe = exports.createRememberMeCookie = exports.COOKIE_NAME = void 0;
const base_path_1 = __importDefault(__webpack_require__(8312));
const uuid_1 = __webpack_require__(509557);
const password_hash_1 = __importDefault(__webpack_require__(987909));
const pool_1 = __importDefault(__webpack_require__(541808));
const util_1 = __webpack_require__(258813);
const cookies_1 = __importDefault(__webpack_require__(972475));
const hash_1 = __importDefault(__webpack_require__(578772));
exports.COOKIE_NAME = `${base_path_1.default.length <= 1 ? "" : encodeURIComponent(base_path_1.default)}remember_me`;
// Create a remember me cookie for the given account_id and store
// it in the database.  The cookie is similar to using a server
// assigned random uuid-v4 as a password.  The user knows the
// uuid-v4, and we only store what it hashes to, so even if
// somebody gets our database, they can't make fake cookies and use
// them to sign in.
async function createRememberMeCookie(account_id, arg_ttl_s) {
    // compute the value and ttl_s:
    const session_id = (0, uuid_1.v4)();
    const hash_session_id = (0, password_hash_1.default)(session_id);
    const x = hash_session_id.split("$");
    const value = [x[0], x[1], x[2], session_id].join("$");
    const ttl_s = arg_ttl_s ?? 24 * 3600 * 30; // 30 days -- seems to work well, but this could be per user configurable, etc.
    // store the cookie in the database
    const pool = (0, pool_1.default)();
    await pool.query("INSERT INTO remember_me (hash, expire, account_id) VALUES($1::TEXT, $2::TIMESTAMP, $3::UUID)", [hash_session_id.slice(0, 127), (0, util_1.expireTime)(ttl_s), account_id]);
    return { value, ttl_s };
}
exports.createRememberMeCookie = createRememberMeCookie;
// delete the remember me database entry for the given hash
async function deleteRememberMe(hash) {
    const pool = (0, pool_1.default)();
    await pool.query("DELETE FROM remember_me WHERE hash=$1::TEXT", [
        hash.slice(0, 127),
    ]);
}
exports.deleteRememberMe = deleteRememberMe;
// delete all remember me cookies for the account
async function deleteAllRememberMe(account_id) {
    const pool = (0, pool_1.default)();
    await pool.query("DELETE FROM remember_me WHERE account_id=$1::UUID", [
        account_id,
    ]);
}
exports.deleteAllRememberMe = deleteAllRememberMe;
function getRememberMeHash(req) {
    const cookies = new cookies_1.default(req);
    const rememberMe = cookies.get(exports.COOKIE_NAME);
    if (!rememberMe) {
        return;
    }
    const x = rememberMe.split("$");
    if (x.length !== 4) {
        throw Error("badly formatted remember_me cookie");
    }
    return (0, hash_1.default)(x[0], x[1], parseInt(x[2]), x[3]).slice(0, 127);
}
exports.getRememberMeHash = getRememberMeHash;
//# sourceMappingURL=remember-me.js.map

/***/ })

};
;