Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You're challenge for today is to create a random password generator!
- For extra credit, allow the user to specify the amount of passwords to generate.
- For even more extra credit, allow the user to specify the length of the strings he wants to generate!
- */
- import java.util.Random;
- import java.util.Scanner;
- public class easy4{
- public static void main(String args[]){
- int userInput = 0;
- int counter = 0;
- String password;
- System.out.println("Welcome to the Random password Generator! \nHow many passwords would you like to generate?");
- counter = input();
- System.out.println("How many characters would you like the passwords to be?");
- userInput = input();
- for(int i = 1; i<=counter; i++){
- password = passwordGenerator(userInput);
- System.out.println("Password " + i + ": " + password);
- }
- }
- public static int input(){
- Scanner inputs = new Scanner(System.in);
- int userInput = inputs.nextInt();
- return userInput;
- }
- public static String passwordGenerator(int userInput){
- StringBuilder passwords = new StringBuilder(userInput);
- String list = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+{}[]<>,.?/"); //List of usable characters
- Random num = new Random();
- for(int i = 0; i<userInput; i++){
- passwords.append(list.charAt(num.nextInt(list.length())));
- }
- String password = passwords.toString();
- return password;
- }
- }
Add Comment
Please, Sign In to add comment