UNPKG

@citrineos/util

Version:

The OCPP util module which supplies helpful utilities like cache and queue connectors, etc.

30 lines 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generatePassword = generatePassword; exports.isValidPassword = isValidPassword; // Copyright Contributors to the CitrineOS Project // // SPDX-License-Identifier: Apache 2.0 const node_crypto_1 = require("node:crypto"); const MIN_LENGTH = 16; const MAX_LENGTH = 40; const LOWERCASE = 'abcdefghijklmnopqrstuvwxyz'; const UPPERCASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; const DIGITS = '0123456789'; const SYMBOLS = '*-_=:+|@.'; const CHARSET = [...LOWERCASE, ...UPPERCASE, ...DIGITS, ...SYMBOLS]; function generatePassword() { return [...(0, node_crypto_1.randomBytes)(MAX_LENGTH)].map((value) => CHARSET[value % CHARSET.length]).join(''); } function isValidPassword(password) { if (password.length < MIN_LENGTH || password.length > MAX_LENGTH) { return false; } for (const char of password) { if (!CHARSET.includes(char)) { return false; } } return true; } //# sourceMappingURL=authentication.js.map