So my task is to make a password generator what makes a pw for the length what the user typed in. It have to consist of numbers, alphabethical letters and symbols.
What did i do wrong? What could i improve in this code?
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int pwLength;
String charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!+#@=&/.,";
char c;
boolean viable = false;
Random rnd = new Random();
while(viable==false){
String[] password;
pwLength = sc.nextInt();
for(int i=0; i<=pwLength;i++){
password[i]=Character.toString(charset.charAt(pwLength = sc.nextInt()));
}
viable=true;
System.out.print("Your password is: " + password);
System.out.print("Your password is " + pwLength + " character long!");
}
}
}
Aucun commentaire:
Enregistrer un commentaire