This program provides the user with options of what kinds of passwords they want, then they can choose from those menu options, then enter how long they want their password to be. The program is supposed to generate random ASCII values for the password(what it is composed of is based on the users menu choice). The program compiles fine without errors. But when the program is run it seems to have a few issues. Sometimes the length works correctly and others it doesnt. And it doesn't seem to reset the password. The password doesnt work correctly at all.

For instance when I want it to have only lower case letters with a legnth of five. It displays 22 random numbers and a password of [C@1777b1. So here is the code I have, Any help would be appreciated!

import java.util.Scanner; 
import java.util.Random; 

public class Password
{
      public static void main(String [] args)
      {
 Scanner in = new Scanner(System.in); 
int enter;
int pass;
int value; 


  
System.out.println("               Password Genration Menu              *");
System.out.println("*********************************************************"); 
System.out.println("   [1] Lowercase Letters");
System.out.println("   [2] Lowercase & Uppercase Letters"); 
System.out.println("   [3] Lowercase, Uppercase, and Numbers");
System.out.println("   [4] Lowercase, Uppercase, Numbers and Puntuation");
System.out.println("   [5] Quit");
System.out.println("*********************************************************"); 

System.out.print("Enter Selection  (1-5): ");
enter =  in.nextInt(); 


System.out.print("Password Length (1-14): "); 

pass =  in.nextInt(); 


if (enter==1) 

{ 
Random randomNumber = new Random(); 

    char password[] = new char[pass];
 
    for (int i = 0; i < pass;) {
 
      value = randomNumber.nextInt(125);
      System.out.println(value);
      if ((value >= 97 && value <= 122)) {
password[i] = (char)value;
        i++;  
    }
} 
System.out.print ("Password: " + (password));
}
  

else if (enter==2) 

{
Random randomNumber = new Random();
 
    char password[] = new char[pass];
 
    for (int i = 0; i < pass;) {
 
      value = randomNumber.nextInt(125);
      System.out.println(value);
      if  ((value >= 65 && value <= 90) || (value >= 97 && value <= 122)) {
 
        password[i] = (char) value;
        i++;
} 
}
System.out.print ("Password: " + (password));
} 

else if (enter==3) 

{ 
Random randomNumber = new Random();
 
    char password[] = new char[pass];
 
    for (int i = 0; i < pass;) {
 
       value = randomNumber.nextInt(125);
      System.out.println(value);
      if ((value >= 48 && value <= 57) || (value >= 65 && value <= 90)
          || (value >= 97 && value <= 122)) {
 
        password[i] = (char) value;
        i++; 

      
    }
} 
System.out.print ("Password: " + (password));
} 

else if (enter==4) 

{
Random randomNumber = new Random();
 
    char password[] = new char[pass];
 
    for (int i = 0; i < pass;) {
 
      value = randomNumber.nextInt(125);
      System.out.println(value);
      if ((value >= 48 && value <= 57) || (value >= 58 && value <= 64) || (value >= 65 && value <= 90)
          || (value >= 97 && value <= 122)) {
 
        password[i] = (char) value;
        i++;
} 
}
System.out.print ("Password: " + (password));
}
else 

{
System.out.println("Goodbye!");
} 

}
}

for example Line:114
Convert char array to String and then write.
Use String constructor: public String(char[] value)

String s = new String(password);
System.out.println("Password: " + s);

or

System.out.println("Password: " + new String(password))

for example Line:114
Convert char array to String and then write.
Use String constructor: public String(char[] value)

String s = new String(password);
System.out.println("Password: " + s);

or

System.out.println("Password: " + new String(password))

Thanks that makes it work!!! Your help was much appreciated!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.