Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.concurrent.ThreadLocalRandom;
- public class Password {
- private static Scanner dd;
- public static void main(String[] args) {
- while (true) {
- password(args);
- }
- }
- public static void password(String[] args) {
- int opt1, opt2, opt3, opt4;
- String num = "0123456789";
- String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- String lower = "abcdefghijklmnopqrstuvwxyz";
- String special = "!#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ";
- String extra = "";
- int log;
- dd = new Scanner(System.in);
- while (true) {
- System.out.print("Insert number: [1=yes / 0=no] ");
- opt1 = dd.nextInt();
- if (opt1 == 1 | opt1 == 0) {
- break;
- }
- }
- while (true) {
- System.out.print("Insert Uppercase letter: [1=yes / 0=no] ");
- opt2 = dd.nextInt();
- if (opt2 == 1 | opt2 == 0) {
- break;
- }
- }
- while (true) {
- System.out.print("Insert lowercase letter: [1=yes / 0=no] ");
- opt3 = dd.nextInt();
- if (opt3 == 1 | opt3 == 0) {
- break;
- }
- }
- while (true) {
- System.out.print("Insert special characters: [1=yes / 0=no] ");
- opt4 = dd.nextInt();
- if (opt4 == 1 | opt4 == 0) {
- break;
- }
- }
- System.out.print("Insert extra characters to add:");
- dd.nextLine();
- extra = dd.nextLine();
- System.out.print("Insert password length: ");
- int leng = dd.nextInt();
- System.out.print("Insert password to generate: ");
- int numb = dd.nextInt();
- StringBuilder password = new StringBuilder();
- int cache = 0;
- while (numb != cache) {
- while (password.length() != leng) {
- log = ThreadLocalRandom.current().nextInt(0, 7);
- if (log == 1 & opt1 == 1) {
- int m = ThreadLocalRandom.current()
- .nextInt(0, num.length());
- char n = num.charAt(m);
- String o = Character.toString(n);
- password.append(o);
- }
- if (log == 2 & opt2 == 1) {
- int m = ThreadLocalRandom.current().nextInt(0,
- upper.length());
- char n = upper.charAt(m);
- String o = Character.toString(n);
- password.append(o);
- }
- if (log == 3 & opt3 == 1) {
- int m = ThreadLocalRandom.current().nextInt(0,
- lower.length());
- char n = lower.charAt(m);
- String o = Character.toString(n);
- password.append(o);
- }
- if (log == 4 & opt4 == 1) {
- int m = ThreadLocalRandom.current().nextInt(0,
- special.length());
- char n = special.charAt(m);
- String o = Character.toString(n);
- password.append(o);
- }
- if (log == 5 & extra.length() != 0) {
- int m = ThreadLocalRandom.current().nextInt(0,
- extra.length());
- char n = extra.charAt(m);
- String o = Character.toString(n);
- password.append(o);
- }
- }
- System.out.println(password);
- cache++;
- password.setLength(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement