From e9b89d14ad1066d9c4d3dd9ebf0f3120e0990b25 Mon Sep 17 00:00:00 2001 From: Thorsten Bylicki <109308073+bylickilabs@users.noreply.github.com> Date: Tue, 1 Jul 2025 23:27:12 +0200 Subject: [PATCH] Create index.ts --- index.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 index.ts diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..fc7415f --- /dev/null +++ b/index.ts @@ -0,0 +1,23 @@ +function generatePassword(length: number, useUpper = true, useLower = true, useDigits = true, useSpecial = true): string { + const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + const lower = 'abcdefghijklmnopqrstuvwxyz'; + const digits = '0123456789'; + const special = '!@#$%^&*()_-+=[]{}|;:,.<>?'; + let chars = ''; + if (useUpper) chars += upper; + if (useLower) chars += lower; + if (useDigits) chars += digits; + if (useSpecial) chars += special; + + if (!chars) throw new Error('Bitte mindestens einen Zeichentyp auswählen!'); + + let password = ''; + for (let i = 0; i < length; i++) { + password += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return password; +} + +// Simple CLI-Ausgabe +const len = Number(process.argv[2]) || 16; +console.log("Generated Password:", generatePassword(len));