UNPKG

@wocker/ws

Version:

Docker workspace for web projects

21 lines (20 loc) 727 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPasswordHash = void 0; const crypto_1 = __importDefault(require("crypto")); const createPasswordHash = (password, salt) => { const saltBuffer = salt ? Buffer.from(salt, "hex") : crypto_1.default.randomBytes(16); if (!salt) { salt = saltBuffer.toString("hex"); } const hash = crypto_1.default.createHmac("sha256", saltBuffer) .update(password) .digest("hex"); return `${hash}:${salt}`; }; exports.createPasswordHash = createPasswordHash;