Skip to content

Commit 2d7ed2b

Browse files
authored
Merge pull request #1 from bylickilabs/bylickilabs-patch-1
Create index.ts
2 parents d0c94c5 + e9b89d1 commit 2d7ed2b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function generatePassword(length: number, useUpper = true, useLower = true, useDigits = true, useSpecial = true): string {
2+
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3+
const lower = 'abcdefghijklmnopqrstuvwxyz';
4+
const digits = '0123456789';
5+
const special = '!@#$%^&*()_-+=[]{}|;:,.<>?';
6+
let chars = '';
7+
if (useUpper) chars += upper;
8+
if (useLower) chars += lower;
9+
if (useDigits) chars += digits;
10+
if (useSpecial) chars += special;
11+
12+
if (!chars) throw new Error('Bitte mindestens einen Zeichentyp auswählen!');
13+
14+
let password = '';
15+
for (let i = 0; i < length; i++) {
16+
password += chars.charAt(Math.floor(Math.random() * chars.length));
17+
}
18+
return password;
19+
}
20+
21+
// Simple CLI-Ausgabe
22+
const len = Number(process.argv[2]) || 16;
23+
console.log("Generated Password:", generatePassword(len));

0 commit comments

Comments
 (0)