Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Bruno Alves
- * @version 8/12/2014
- * Generate random password
- */
- import java.util.Scanner;
- public class Password {
- public static void main(String[] args) {
- Scanner kb = new Scanner(System.in);
- int choice,length,counter = 0,rand, uporlower,num,randpunc;
- 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
- 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'};
- char[] punc = {'[',']','(',')','|','{','}','~'}; //8
- String pass = "";
- System.out.println(" Password Generation Menu ");
- System.out.println("********************************************************");
- System.out.println("* [1] Lowercase Letters *");
- System.out.println("* [2] Lowercase & Uppercase Letters *");
- System.out.println("* [3] Lowercase, Uppercase, and Numbers *");
- System.out.println("* [4] Lowercase, Uppercase, Numbers, and Punctuation *");
- System.out.println("* [5] Quit *");
- System.out.println("********************************************************");
- System.out.print("Enter Selection (1-5): ");
- choice = kb.nextInt();
- System.out.println();
- System.out.print("Password Length (1-14): ");
- length = kb.nextInt();
- System.out.println();
- switch(choice)
- {
- case 1:
- while(counter < length)
- {
- rand = 0 + (int)(Math.random()*25);
- pass = pass + lower[rand];
- counter++;
- }
- break;
- case 2:
- while(counter < length)
- {
- uporlower = 0 + (int)(Math.random()*2);
- rand = 0 + (int)(Math.random()*25);
- if (uporlower == 0)
- {
- pass = pass + lower[rand];
- }
- else
- {
- pass = pass + upper[rand];
- }
- counter++;
- }
- break;
- case 3:
- while(counter < length)
- {
- uporlower = 0 + (int)(Math.random()*2);
- num = 0 + (int)(Math.random()*9);
- rand = 0 + (int)(Math.random()*25);
- if (uporlower == 0)
- {
- pass = pass + lower[rand] + num;
- }
- else
- {
- pass = pass + upper[rand] + num;
- }
- counter++;
- }
- break;
- case 4:
- while(counter < length)
- {
- uporlower = 0 + (int)(Math.random()*2);
- num = 0 + (int)(Math.random()*9);
- rand = 0 + (int)(Math.random()*25);
- randpunc = 0 + (int)(Math.random()*7);
- if (uporlower == 0)
- {
- pass = pass + lower[rand] + num + punc[randpunc];
- }
- else
- {
- pass = pass + upper[rand] + num + punc[randpunc];
- }
- counter++;
- }
- break;
- case 5:
- System.out.println("Bye!");
- break;
- }
- System.out.println(pass);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement