Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 java password generator stuck
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2, 3
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: Thu Nov 24, 2011 2:00 pm   Post subject: RE:java password generator stuck

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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
ImDennis




PostPosted: 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, Very Happy 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 Razz 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




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: 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




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: 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




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: Thu Nov 24, 2011 5:02 pm   Post subject: Re: RE:java password generator stuck

Tony @ Thu Nov 24, 2011 5:00 pm wrote:
that's right. Now, after you generate all of the characters, you'd have to figure out how to print it all.


okay well is there any way you can tell me how i can print results of it outside the loop? cuz if i put it inside the loop like
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


it starts each letter on a seperate line, could i do a while loop to have it print out? while it does the loop?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 24, 2011 5:05 pm   Post subject: RE:java password generator stuck

I said that you should print after the loop is over and you have the entire password generated.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: Thu Nov 24, 2011 5:09 pm   Post subject: Re: RE:java password generator stuck

Tony @ Thu Nov 24, 2011 5:05 pm wrote:
I said that you should print after the loop is over and you have the entire password generated.


so should i convert the char into a string and it print outside the loop after, does that make sense to u?
Tony




PostPosted: Thu Nov 24, 2011 5:58 pm   Post subject: RE:java password generator stuck

as long as it's all of the chars, and not just a single char (your statement is ambiguous), that would work.

alternatively, print (and println) do support
Quote:

public void println(char[] x)

definition.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: 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 Very Happy 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




PostPosted: 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

lol, what?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
ImDennis




PostPosted: 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 Razz
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 3  [ 44 Posts ]
Goto page Previous  1, 2, 3
Jump to:   


Style:  
Search: