"use strict";function makeRandomString32(){return crypto_1.default.randomBytes(32).toString("hex")}async function hashPassword(e){try{return await argon2_1.default.hash(e)}catch(e){throw(0,error_1.createError)({statusCode:500,message:e.message})}}function makeUuid(){return(0,uuid_1.v4)()}async function generateNewPassword(e){const r=generate_password_1.default.generate({length:20,numbers:!0,symbols:!0,strict:!0});try{validatePassword(r)}catch(e){throw(0,error_1.createError)({statusCode:400,message:e.message})}try{const t=await hashPassword(r);await db_1.models.user.update({password:t},{where:{id:e}});return r}catch(e){console_1.logger.error("AUTH","Error generating new password",e);throw(0,error_1.createError)({statusCode:500,message:e.message})}}async function verifyPassword(e,r){return!!await argon2_1.default.verify(e,r)}function validatePassword(e){return!(e.length<8)&&(!!/[A-Z]/.test(e)&&(!!/[a-z]/.test(e)&&(!!/\d/.test(e)&&!!/\W/.test(e))))}var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.makeRandomString32=makeRandomString32;exports.hashPassword=hashPassword;exports.makeUuid=makeUuid;exports.generateNewPassword=generateNewPassword;exports.verifyPassword=verifyPassword;exports.validatePassword=validatePassword;const argon2_1=__importDefault(require("argon2")),crypto_1=__importDefault(require("crypto")),generate_password_1=__importDefault(require("generate-password")),uuid_1=require("uuid"),error_1=require("./error"),db_1=require("@b/db"),console_1=require("./console");