"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;
var 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).
var HASH_ALGORITHM = "sha512";
var HASH_ITERATIONS = 1000;
var 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

/***/ }),

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


var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.deleteAllRememberMe = exports.deleteRememberMe = exports.createRememberMeCookie = exports.COOKIE_NAME = void 0;
var base_path_1 = __importDefault(__webpack_require__(8312));
var uuid_1 = __webpack_require__(509557);
var password_hash_1 = __importDefault(__webpack_require__(987909));
var pool_1 = __importDefault(__webpack_require__(541808));
var util_1 = __webpack_require__(258813);
exports.COOKIE_NAME = "".concat(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.
function createRememberMeCookie(account_id, arg_ttl_s) {
    return __awaiter(this, void 0, void 0, function () {
        var session_id, hash_session_id, x, value, ttl_s, pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    session_id = (0, uuid_1.v4)();
                    hash_session_id = (0, password_hash_1.default)(session_id);
                    x = hash_session_id.split("$");
                    value = [x[0], x[1], x[2], session_id].join("$");
                    ttl_s = arg_ttl_s !== null && arg_ttl_s !== void 0 ? arg_ttl_s : 24 * 3600 * 30;
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, 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])];
                case 1:
                    _a.sent();
                    return [2 /*return*/, { value: value, ttl_s: ttl_s }];
            }
        });
    });
}
exports.createRememberMeCookie = createRememberMeCookie;
// delete the remember me database entry for the given hash
function deleteRememberMe(hash) {
    return __awaiter(this, void 0, void 0, function () {
        var pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("DELETE FROM remember_me WHERE hash=$1::TEXT", [
                            hash.slice(0, 127),
                        ])];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports.deleteRememberMe = deleteRememberMe;
// delete all remember me cookies for the account
function deleteAllRememberMe(account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("DELETE FROM remember_me WHERE account_id=$1::UUID", [
                            account_id,
                        ])];
                case 1:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports.deleteAllRememberMe = deleteAllRememberMe;
//# sourceMappingURL=remember-me.js.map

/***/ })

};
;