Advertisement
bha2597

Password

Aug 12th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. /**
  2.  * @author Bruno Alves
  3.  * @version 8/12/2014
  4.  * Generate random password
  5.  */
  6.  
  7. import java.util.Scanner;
  8.  
  9.  
  10. public class Password {
  11.  
  12.  
  13.     public static void main(String[] args) {
  14.        
  15.         Scanner kb = new Scanner(System.in);
  16.  
  17.        
  18.        
  19.         int choice,length,counter = 0,rand, uporlower,num,randpunc;
  20.         char[] lower = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','u','r','s','t','v','w','x','y','z'}; //26
  21.         char[] upper = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','U','R','S','T','V','W','X','Y','Z'};
  22.         char[] punc = {'[',']','(',')','|','{','}','~'}; //8
  23.         String pass = "";
  24.        
  25.         System.out.println("                Password Generation Menu                ");
  26.         System.out.println("********************************************************");
  27.         System.out.println("*  [1] Lowercase Letters                               *");
  28.         System.out.println("*  [2] Lowercase & Uppercase Letters                   *");  
  29.         System.out.println("*  [3] Lowercase, Uppercase, and Numbers               *");
  30.         System.out.println("*  [4] Lowercase, Uppercase, Numbers, and Punctuation  *");
  31.         System.out.println("*  [5] Quit                                            *");
  32.         System.out.println("********************************************************");
  33.        
  34.        
  35.         System.out.print("Enter Selection (1-5): ");
  36.         choice = kb.nextInt();
  37.         System.out.println();
  38.        
  39.         System.out.print("Password Length (1-14): ");
  40.         length = kb.nextInt();
  41.         System.out.println();
  42.  
  43.         switch(choice)
  44.         {
  45.         case 1:
  46.             while(counter < length)
  47.             {
  48.                 rand = 0 + (int)(Math.random()*25);
  49.                 pass = pass + lower[rand];
  50.                 counter++;
  51.             }
  52.             break;
  53.            
  54.         case 2:
  55.             while(counter < length)
  56.             {
  57.                 uporlower = 0 + (int)(Math.random()*2);
  58.                 rand = 0 + (int)(Math.random()*25);
  59.                 if (uporlower == 0)
  60.                 {
  61.                     pass = pass + lower[rand];
  62.                 }
  63.                 else
  64.                 {
  65.                     pass = pass + upper[rand];
  66.                 }
  67.                 counter++;
  68.             }
  69.             break;
  70.            
  71.         case 3:
  72.             while(counter < length)
  73.             {
  74.                 uporlower = 0 + (int)(Math.random()*2);
  75.                 num = 0 + (int)(Math.random()*9);
  76.                 rand = 0 + (int)(Math.random()*25);
  77.                 if (uporlower == 0)
  78.                 {
  79.                     pass = pass + lower[rand] + num;
  80.                 }
  81.                 else
  82.                 {
  83.                     pass = pass + upper[rand] + num;
  84.                 }
  85.                 counter++;
  86.             }
  87.             break;
  88.            
  89.         case 4:
  90.             while(counter < length)
  91.             {
  92.                 uporlower = 0 + (int)(Math.random()*2);
  93.                 num = 0 + (int)(Math.random()*9);
  94.                 rand = 0 + (int)(Math.random()*25);
  95.                 randpunc = 0 + (int)(Math.random()*7);
  96.                 if (uporlower == 0)
  97.                 {
  98.                     pass = pass + lower[rand] + num + punc[randpunc];
  99.                 }
  100.                 else
  101.                 {
  102.                     pass = pass + upper[rand] + num + punc[randpunc];
  103.                 }
  104.                 counter++;
  105.             }
  106.             break;
  107.            
  108.         case 5:
  109.             System.out.println("Bye!");
  110.             break;
  111.         }
  112.         System.out.println(pass);
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement