Advertisement
Dar954826

Password[ITA].java

Feb 26th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.79 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.concurrent.ThreadLocalRandom;
  3.  
  4. public class Password {
  5.     private static Scanner dd;
  6.     public static void main(String[] args) {
  7.         while (true) {
  8.             password(args);
  9.         }
  10.     }
  11.  
  12.     public static void password(String[] args) {
  13.         int opt1, opt2, opt3, opt4;
  14.         String num = "0123456789";
  15.         String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  16.         String lower = "abcdefghijklmnopqrstuvwxyz";
  17.         String special = "!#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ";
  18.         String extra = "";
  19.         int log;
  20.         dd = new Scanner(System.in);
  21.         while (true) {
  22.             System.out.print("Inserire numeri: [1=si / 0=no] ");
  23.             opt1 = dd.nextInt();
  24.             if (opt1 == 1 | opt1 == 0) {
  25.                 break;
  26.             }
  27.         }
  28.         while (true) {
  29.             System.out.print("Inserire lettere maiuscole: [1=si / 0=no] ");
  30.             opt2 = dd.nextInt();
  31.             if (opt2 == 1 | opt2 == 0) {
  32.                 break;
  33.             }
  34.         }
  35.         while (true) {
  36.             System.out.print("Inserire lettere minuscole: [1=si / 0=no] ");
  37.             opt3 = dd.nextInt();
  38.             if (opt3 == 1 | opt3 == 0) {
  39.                 break;
  40.             }
  41.         }
  42.         while (true) {
  43.             System.out.print("Inserire caratteri speciali: [1=si / 0=no] ");
  44.             opt4 = dd.nextInt();
  45.             if (opt4 == 1 | opt4 == 0) {
  46.                 break;
  47.             }
  48.         }
  49.         System.out.print("Inserire caratteri extra da aggiungere:");
  50.         dd.nextLine();
  51.         extra = dd.nextLine();
  52.  
  53.         System.out.print("Inserisci lunghezza password: ");
  54.         int leng = dd.nextInt();
  55.         System.out.print("Inserisci password da generare: ");
  56.         int numb = dd.nextInt();
  57.         StringBuilder password = new StringBuilder();
  58.         int cache = 0;
  59.         while (numb != cache) {
  60.             while (password.length() != leng) {
  61.                 log = ThreadLocalRandom.current().nextInt(0, 7);
  62.                 if (log == 1 & opt1 == 1) {
  63.                     int m = ThreadLocalRandom.current()
  64.                             .nextInt(0, num.length());
  65.                     char n = num.charAt(m);
  66.                     String o = Character.toString(n);
  67.                     password.append(o);
  68.                 }
  69.                 if (log == 2 & opt2 == 1) {
  70.                     int m = ThreadLocalRandom.current().nextInt(0,
  71.                             upper.length());
  72.                     char n = upper.charAt(m);
  73.                     String o = Character.toString(n);
  74.                     password.append(o);
  75.                 }
  76.                 if (log == 3 & opt3 == 1) {
  77.                     int m = ThreadLocalRandom.current().nextInt(0,
  78.                             lower.length());
  79.                     char n = lower.charAt(m);
  80.                     String o = Character.toString(n);
  81.                     password.append(o);
  82.                 }
  83.                 if (log == 4 & opt4 == 1) {
  84.                     int m = ThreadLocalRandom.current().nextInt(0,
  85.                             special.length());
  86.                     char n = special.charAt(m);
  87.                     String o = Character.toString(n);
  88.                     password.append(o);
  89.                 }
  90.                 if (log == 5 & extra.length() != 0) {
  91.                     int m = ThreadLocalRandom.current().nextInt(0,
  92.                             extra.length());
  93.                     char n = extra.charAt(m);
  94.                     String o = Character.toString(n);
  95.                     password.append(o);
  96.                 }
  97.             }
  98.             System.out.println(password);
  99.             cache++;
  100.             password.setLength(0);
  101.         }
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement