Last active
January 12, 2022 17:27
-
-
Save luisoos/b7f11236c0efe736299f8e48fbeb9764 to your computer and use it in GitHub Desktop.
Java Password Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// Giving advice to user | |
System.out.println("How much characters should your password have?"); | |
// Get user input | |
Scanner scanner = new Scanner(System.in); | |
int length = scanner.nextInt(); | |
// Declaring available characters | |
String characters = "1234567890!§$%&/()=?QWERTZUIOPASDFGHJKLYXCVBNMqwertzuiopasdfghjklyxcvbnm.:,;-_#+^<>"; | |
// Generate random password | |
Random random = new Random(); | |
char[] password = new char[length]; | |
for (int i = 0; i < length; i++) { | |
password[i] = characters.charAt(random.nextInt(characters.length())); | |
} | |
// Print out the password | |
System.out.println(password); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment