Created
December 19, 2019 12:32
-
-
Save JosiasAurel/7dbcd561d2e8c470df5ed483eb8207e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
public class PasswordGenerator | |
{ | |
public static void main(String[] args) | |
{ | |
int length = 10; // password length | |
System.out.println(generatePswd(length)); | |
} | |
static char[] generatePswd(int len) | |
{ | |
System.out.println("Your Password:"); | |
String charsCaps = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | |
String chars = "abcdefghijklmnopqrstuvwxyz"; | |
String nums = "0123456789"; | |
String symbols = "!@#$%^&*_=+-/€.?<>)"; | |
String passSymbols = charsCaps + chars + nums + symbols; | |
Random rnd = new Random(); | |
char[] password = new char[len]; | |
int index = 0; | |
for (int i = 0; i < len; i++) | |
{ | |
password[i] = passSymbols.charAt(rnd.nextInt(passSymbols.length())); | |
} | |
return password; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment