UNPKG

@citrineos/util

Version:

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

26 lines 882 B
// SPDX-FileCopyrightText: 2025 Contributors to the CitrineOS Project // // SPDX-License-Identifier: Apache-2.0 import { randomBytes } from '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]; export function generatePassword() { return [...randomBytes(MAX_LENGTH)].map((value) => CHARSET[value % CHARSET.length]).join(''); } export 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