Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -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));
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.random() is not cryptographically secure; consider using Node.js crypto.randomInt or crypto.getRandomValues to generate secure random indexes for password characters.

Suggested change
password += chars.charAt(Math.floor(Math.random() * chars.length));
password += chars.charAt(crypto.randomInt(0, chars.length));

Copilot uses AI. Check for mistakes.
}
return password;
}

// Simple CLI-Ausgabe
const len = Number(process.argv[2]) || 16;
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User input for password length should be validated to ensure it's a positive integer; currently invalid or negative values may produce unexpected results or default silently to 16.

Suggested change
const len = Number(process.argv[2]) || 16;
const inputLength = process.argv[2];
const len = parseInt(inputLength, 10);
if (isNaN(len) || len <= 0) {
throw new Error("Invalid password length. Please provide a positive integer.");
}

Copilot uses AI. Check for mistakes.
console.log("Generated Password:", generatePassword(len));