Posted: Thu Nov 24, 2011 4:10 pm Post subject: Re: RE:java password generator stuck
Velocity @ Thu Nov 24, 2011 1:41 pm wrote:
why dont you just put your array in char form array of 1 .. 255, so it includes every single possible character.
yea i didn't think of this, i changed my stuff
Tony @ Thu Nov 24, 2011 2:00 pm wrote:
because some of the characters (including those between 0 to 69 (why did you pick this range?)) are non-printable control characters.
Also, what's the point of having a loop, if it always breaks out and never does a second iteration?
i was thinking cuz of the array size but i changed it, so now i got it to randomly generate numbers, heres what i got so far, but i cant figure out why each character is on a separate line, any suggestions?
Quote:
//start 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 for loop
Tony
Posted: Thu Nov 24, 2011 4:19 pm Post subject: Re: RE:java password generator stuck
This is looking much better, you're almost there ImDennis!
ImDennis @ Thu Nov 24, 2011 4:10 pm wrote:
why each character is on a separate line, any suggestions?
Well, how many times does "your password is " appears in the output?
Posted: Thu Nov 24, 2011 4:24 pm Post subject: Re: RE:java password generator stuck
Tony @ Thu Nov 24, 2011 4:19 pm wrote:
This is looking much better, you're almost there ImDennis!
ImDennis @ Thu Nov 24, 2011 4:10 pm wrote:
why each character is on a separate line, any suggestions?
Well, how many times does "your password is " appears in the output?
it appears exact amount of times as user asked , but it breaks it down in seperate lines, so i figured it must be cuz system.out.println is within the loop right? so when i took it out i got an error cuz [i] doesnt work outside the loop, so hers what i got
Quote:
char [] passwordArray = new char[userChoice];
for(char i = 0; i < passwordArray.length; i++)
{
passwordArray[i] = (char)(Math.random() * 122 + 33);
}//end for loop
System.out.print("your password is " + passwordArray[i] );
Tony
Posted: Thu Nov 24, 2011 4:43 pm Post subject: RE:java password generator stuck
Right, what is the value of i when you exit the loop?
Besides, what does passwordArray[i] (for any value of i) mean? Is that your entire password?
Posted: Thu Nov 24, 2011 4:50 pm Post subject: Re: RE:java password generator stuck
Tony @ Thu Nov 24, 2011 4:43 pm wrote:
Right, what is the value of i when you exit the loop?
Besides, what does passwordArray[i] (for any value of i) mean? Is that your entire password?
okay so i got " int userChoice = 0; " which gives the user a choice to enter the limit, then i got " char [] passwordArray = new char[userChoice];" which takes the char array and makes it into a newchar of userchoice (kinda like a limiter, so it goes up to how many the user wants), then i got " for(char i = 0; i < passwordArray.length; i++)
{passwordArray[i] = (char)(Math.random() * 122 + 33)
which generates the password, random chars step by step
Tony
Posted: Thu Nov 24, 2011 5:00 pm Post subject: RE:java password generator stuck
that's right. Now, after you generate all of the characters, you'd have to figure out how to print it all.
Posted: Sun Nov 27, 2011 11:56 am Post subject: Re: java password generator stuck
oh sorry forgot to upload the code, after a bit of struggling i managed to get the code working to my approval and satisfaction if u want u can edit it or make it better
Quote:
/**
* Program Name:D_A_PasswordGenerator.java
* Purpose: generate random secure password to be used!
* Coder:Denis Aleta
* Date:Nov 23, 2011
*/
import java.util.Scanner;
public class D_A_PasswordGenerator
{
public static void main(String[] args)
{
// Create Scanner object
Scanner input = new Scanner(System.in);
// Tell user what the program will do
System.out.println("This program will randomly generate a password for you");
// create variables
int userChoice = 0;
//ask user how many characters they want (minimum 6, maximum 16)
System.out.print("\nplease enter how many characters do you want in your password (minimum 6, maximum 16)? ");
userChoice = input.nextInt();
//make sure that user input is valid
if (userChoice < 6 || userChoice > 16)
{
System.out.println("not a valid input");
return;
}
//loop
char [] passwordArray = new char[userChoice];
for(char i = 0; i < passwordArray.length; i++)
{
passwordArray[i] = (char)(Math.random() * 122 + 33);
}//end for loop
//new loop to generate random password
String randomPassword = ""; //used to hold the random password
for(int i = 0; i != userChoice; ++i)
{
randomPassword = randomPassword + passwordArray [i]; //connect password array with random password
}
int iterations = (int)(Math.random()*25 + 1); //randomly generate a number to trick the user to thinking the program works
//print out results
System.out.println("\nyour password is: " + randomPassword);
System.out.println("it took a total of " + iterations +" iterations"+ " to get your new password, which is " + randomPassword);
}
//end main
}
//end class
Tony
Posted: Sun Nov 27, 2011 12:32 pm Post subject: RE:java password generator stuck
Quote:
//randomly generate a number to trick the user to thinking the program works
Posted: Sun Nov 27, 2011 12:56 pm Post subject: Re: RE:java password generator stuck
Tony @ Sun Nov 27, 2011 12:32 pm wrote:
Quote:
//randomly generate a number to trick the user to thinking the program works
lol, what?
instead of doing actual number of times to generate the password without certain ASCIIs i got lazy and just put a random generator to make it look like it actually takes try to generate