Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help! Password Generator

902123Nov 25 2011 — edited Nov 25 2011
Hi, so I am a student in Computer Programming, and I have a project due this morning.
I'm working on a password generator that fulfils these requirements:

Code must compile and run without crashing.

Program must explain what it will do and tell user what the acceptable
range of inputs is. Data validation of user input must be done.

Loop structure must be set up to generate characters. Characters
generated must be in the proper range and validated before being placed
in the array.

Candidate password must be tested on all five conditions. Successful
candidate must be converted to a String object for output.

Final output must show the valid generated password and tell how many
iterations it took to generate the password.

The problems I am having are that my program is:
- Restating the statement "Your password is".
- Outputting random characters that I did not put in the hex characters.

Here is my code for anyone who wants to look it over:

Start of Code

import java.util.Scanner;
public class T_H_PasswordGenerator
{

public static void main(String[] args)

{
Scanner input = new Scanner(System.in);
int userChoice;
int randomHex;

// Tell the user what the program does.
System.out.println("This program will randomly generate a password for you");

// Prompt the user.
System.out.println("Please enter how many characters do you want in your password? (6 - 12 characters)");
userChoice = input.nextInt();

// Create hex characters.
char[] arrayHex = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u',
'v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
'Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9',
'$','#','@','*','/','^' };


// Start of loop.

char [] passwordArray = new char[userChoice];

for(char i = 0; i < passwordArray.length; i++)
{
passwordArray[i] = (char)(Math.random() * 122 + 33);

System.out.print("your password is " + passwordArray[i] );
}

// End of loop.

}
}


End of Code

If anyone can help me, it'd be greatly appreciated!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 23 2011
Added on Nov 25 2011
2 comments
190 views