Frage Passwort Generator Fehle

  • Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

MapHD

Neues Mitglied
23 Dezember 2017
24
0
1
14
#1
Ich will einen Passwort Generator bauen aber wenn ich eine Anzahl an Passwortlänge eingebe kommt z.B.: nur Zahlen.

Hier ist der Code:

Java:
import java.util.Random;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc =new Scanner(System.in);

        System.out.printf("Geben Sie die Länge des Passwortes ein: ");
        int anz= sc.nextInt();

        Random r = new Random();
        int randz = 1 + r.nextInt(4);


        for (int i=0;i<anz;i++) {

            switch (randz){
                case 1:
                    Random r1 = new Random();
                    int randz1 = 1 + r1.nextInt(9);

                        switch (randz1) {

                            case 1:
                                System.out.print("1");
                            break;

                            case 2:
                                System.out.print("2");
                            break;

                            case 3:
                                System.out.print("3");
                            break;

                            case 4:
                                System.out.print("4");
                                break;

                            case 5:
                                System.out.print("5");
                                break;

                            case 6:
                                System.out.print("6");
                                break;

                            case 7:
                                System.out.print("7");
                                break;

                            case 8:
                                System.out.print("8");
                                break;

                            default:
                                System.out.print("9");

                        }

                break;

                case 2:
                    Random r2 = new Random();
                    int randz2 = 1 + r2.nextInt(26);

                    switch (randz2) {

                        case 1:
                            System.out.print("a");
                            break;

                        case 2:
                            System.out.print("b");
                            break;

                        case 3:
                            System.out.print("c");
                            break;

                        case 4:
                            System.out.print("d");
                            break;

                        case 5:
                            System.out.print("e");
                            break;

                        case 6:
                            System.out.print("f");
                            break;

                        case 7:
                            System.out.print("g");
                            break;

                        case 8:
                            System.out.print("h");
                            break;

                        case 9:
                            System.out.print("i");
                            break;

                        case 10:
                            System.out.print("j");
                            break;

                        case 11:
                            System.out.print("k");
                            break;

                        case 12:
                            System.out.print("l");
                            break;

                        case 13:
                            System.out.print("m");
                            break;

                        case 14:
                            System.out.print("n");
                            break;

                        case 15:
                            System.out.print("o");
                            break;

                        case 16:
                            System.out.print("p");
                            break;

                        case 17:
                            System.out.print("q");
                            break;

                        case 18:
                            System.out.print("r");
                            break;

                        case 19:
                            System.out.print("s");
                            break;

                        case 20:
                            System.out.print("t");
                            break;

                        case 21:
                            System.out.print("u");
                            break;

                        case 22:
                            System.out.print("v");
                            break;

                        case 23:
                            System.out.print("w");
                            break;

                        case 24:
                            System.out.print("x");
                            break;

                        case 25:
                            System.out.print("y");
                            break;

                        default:
                            System.out.print("z");

                    }
                    break;


                case 3:
                    Random r3 = new Random();
                    int randz3 = 1 + r3.nextInt(26);

                    switch (randz3) {

                        case 1:
                            System.out.print("A");
                            break;

                        case 2:
                            System.out.print("B");
                            break;

                        case 3:
                            System.out.print("C");
                            break;

                        case 4:
                            System.out.print("D");
                            break;

                        case 5:
                            System.out.print("E");
                            break;

                        case 6:
                            System.out.print("F");
                            break;

                        case 7:
                            System.out.print("G");
                            break;


                        case 8:
                            System.out.print("H");
                            break;


                        case 9:
                            System.out.print("I");
                            break;

                        case 10:
                            System.out.print("J");
                            break;

                        case 11:
                            System.out.print("K");
                            break;

                        case 12:
                            System.out.print("L");
                            break;

                        case 13:
                            System.out.print("M");
                            break;

                        case 14:
                            System.out.print("N");
                            break;

                        case 15:
                            System.out.print("O");
                            break;

                        case 16:
                            System.out.print("P");
                            break;

                        case 17:
                            System.out.print("Q");
                            break;

                        case 18:
                            System.out.print("R");
                            break;

                        case 19:
                            System.out.print("S");
                            break;

                        case 20:
                            System.out.print("T");
                            break;

                        case 21:
                            System.out.print("U");
                            break;

                        case 22:
                            System.out.print("V");
                            break;

                        case 23:
                            System.out.print("W");
                            break;

                        case 24:
                            System.out.print("X");
                            break;

                        case 25:
                            System.out.print("Y");
                            break;

                        default:
                            System.out.print("Z");
                    }
                break;

                case 4:
                    Random r4 = new Random();
                    int rand4 = 1 + r4.nextInt(3);

                    switch (rand4) {

                        case 1:
                            System.out.print(".");
                            break;

                        case 2:
                            System.out.print("!");
                            break;

                        case 3:
                            System.out.print("?");
                            break;

                    }

            }
        }
    }
}