Skip to content

Instantly share code, notes, and snippets.

@JosiasAurel
Created December 19, 2019 12:32
Show Gist options
  • Save JosiasAurel/7dbcd561d2e8c470df5ed483eb8207e3 to your computer and use it in GitHub Desktop.
Save JosiasAurel/7dbcd561d2e8c470df5ed483eb8207e3 to your computer and use it in GitHub Desktop.
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