Thumbs upPWD Generator [+SOURCE]

PollRate It!
7 votes
Posts 1–13 of 13 · Page 1 of 1
PWD Generator [+SOURCE]
Thanks to Hassan, for the main part of this program. Simple but effective password generator. 4 levels:

  • low - upper and lower case letters
  • med - upper and lower case letters with 0-9 numbers
  • high - upper and lower case letters with 0-9 numbers with simple symbols
  • super - upper and lower case letters with 0-9 numbers with all symbols


Only problem I found was if you type in a letter for the "how many characters should it be?" then it will keep repeating...I have no clue why. Anyways, I will be using this and it might be useful to others too so attached is the files, has both 32 and 64 bit versions. Source code provided below:

Code:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
	string cmd,pwd;
	int lng = 0;
	
	string low = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
	string med = "Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9KkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
	string high = "Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9Kk!Ll@Mm#Nn$Oo%Pp^Qq&Rr*Ss(Tt)Uu_Vv-Ww+Xx=YyZz";
	string super = "[A!a@B#b$C^c%D&d*E(e)F{f}G`g~H:h;I'i|J<j>K,k.L/l?M\m=N+n-O_o1P2p3Q4q5R6r7S8s9T0tUuVvWwXxYyZz]";
	
	gen:
		cout << "how strong? low, med, high, or super? ";
		cin >> cmd;
		cout << "how many characters should it be? ";
		cin >> lng;
		
		if(cmd=="low"){
			for(int i = 0; i < lng; ++i){
				pwd += low[rand() % (low.length())];
			}
			cout << pwd.c_str() << endl;
			cin.get();
		}
		if(cmd=="med"){
			for(int i = 0; i < lng; ++i){
				pwd += med[rand() % (med.length())];
			}
			cout << pwd.c_str() << endl;
			cin.get();
		}
		if(cmd=="high"){
			for(int i = 0; i < lng; ++i){
				pwd += high[rand() % (high.length())];
			}
			cout << pwd.c_str() << endl;
			cin.get();
		}
		if(cmd=="super"){
			for(int i = 0; i < lng; ++i){
				pwd += super[rand() % (super.length())];
			}
			cout << pwd.c_str() << endl;
			cin.get();
		}
		if(cmd==""){
			cout << "invalid input!" << endl;
		}
		
	pwd.clear();
	goto gen;
	return 0;
}
very simple I know, but hey it works for what its made for...right?
32 and 64 bit why? I have no clue, it's just cool, just yesterday I got it to compile 64-bit right so yeah lol.

Hassan's Edit: Removed attachment. Can't approve compiled stuff.
Goto command :eek
Good job though.
"Only problem I found was if you type in a letter for the "how many characters should it be?" then it will keep repeating..."
^This is because you would be passing a character when the program is expecting an int. Needless to say, this is bad.
I'm not a pro, but I'd say use While instead of goto:. And just like u said. Its simple, but effective. Don't know for how much time you've been coding, but its cool.
Quote Originally Posted by master131 View Post
goto in C++ is bad practice. :3
That's the thing that always puzzles me about c++. Goto is such a stupid method that causes major spaghetti code, but i don't know why they created goto in the first place. From the start it's obviously a bad idea.
Quote Originally Posted by 258456 View Post
That's the thing that always puzzles me about c++. Goto is such a stupid method that causes major spaghetti code, but i don't know why they created goto in the first place. From the start it's obviously a bad idea.
It was obviously made for a reason, so you shouldn't say it was a bad idea from the start. Many people say that it's bad just because others do, but how many people know a reason other than "it's inefficient" or "bad practice." The efficiency reason doesn't hold much anymore anyways. With a typical computer having 4+ GB of RAM and processors like i5 or i7, we have too much resources for somebody to pull that excuse.
Quote Originally Posted by Auxilium View Post


It was obviously made for a reason, so you shouldn't say it was a bad idea from the start. Many people say that it's bad just because others do, but how many people know a reason other than "it's inefficient" or "bad practice." The efficiency reason doesn't hold much anymore anyways. With a typical computer having 4+ GB of RAM and processors like i5 or i7, we have too much resources for somebody to pull that excuse.
My reason is that it makes code too messy, i could probably use it on a small app, but i don't work on small apps so having a goto here and there is just too much confusion to be able to work and update my app. I don't need to spend valuable hours remembering why i have that goto there and where it goes and what does it do when it gets there and all that. That's my reason. It's a valid reason, and it's true for most people, but if you like working with gotos then good for you, you have a style of coding that you understand easily when using gotos. As for me, i don't like to have spaghetti code. I like everything neat so that two years from now i would be able know what it's doing fast and manage the code.
Quote Originally Posted by 258456 View Post
I don't need to spend valuable hours remembering why i have that goto there and where it goes and what does it do when it gets there and all that.
Don't you comment?
@Web-Designer: I cannot approve the attachment because;

1: No Virus Scans.
2: It is compiled. Means, I cannot check the code for safety. You should provide me the code for both x86 and x64 bit and I'll compile and include it in your original post.

Attachment Removed for Now.
To fix the problem with it repeating when you enter a char and to make sure you can only type in med low high and super do some checking to make sure the input isn't a char when you enter the length, and make sure that the only input can be med low high and super.

Also use a while statement to loop the code instead of a goto. Looks better
"GOTO LABEL" is very procedual beter just avoid that.
either u can wrap the procedure between a function
or just an do/while/for~w/e loop


and there is like 4sequences of code that is almost the same.
beside one variable {low,mid...}
u can probly just declare a var for that
Code:
string Pattern;

//U can still use the if {}
If(cmd = "low") Pattern = low;
//use elseif to avoid unneed reevaluation
ElseIf (cmd = "mid") //... 

//but when u have a bunch of if/elseif, use select
switch(cmd)
{
case "low" : Pattern = low;
//..
default : cout << "unvalid something something"<<endl;
}
Code:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
	char ret;
	int str,len;
	string PWStrength[] = {"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",
							"Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9KkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",
							"Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9Kk!Ll@Mm#Nn$Oo%Pp^Qq&Rr*Ss(Tt)Uu_Vv-Ww+Xx=YyZz",
							"[A!a@B#b$C^c%D&d*E(e)F{f}G`g~H:h;I'i|J<j>K,k.L/l?M\m=N+n-O_o1P2p3Q4q5R6r7S8s9T0tUuVvWwXxYyZz]" };

	while(true)
	{
		cout << "how strong?" << endl << "1- low" << endl << "2- med," << endl << "3- high"  << endl << "4- super" <<endl;
		while(true)
		{
			cin >> str;
			if (0 <= str & str <= 3) break; //validing index
			cout << "Please input a valid number between 1 and 4" << endl;
		}
		while(true)
		{
			cout << "how many characters should it be? " << endl;;
			cin >> len;
			if (6 <= len & len <= 32) break;
		}

		for(int i = 0; i < len; i++)
			cout << PWStrength[str][rand() % PWStrength[str].length()];
		cout << endl;

		while(true)
		{
			cout << "Generate another PW? Y/N" << endl;
			cin >> ret;
			switch(toupper(ret))
			{
				case 'Y' : break;
				case 'N' : return 0;
				default : continue;
			}
		}
	}
	return 0;
}
Would you look at that. This guy must have broken some kind of record
Quote Originally Posted by .::SCHiM::. View Post
Would you look at that. This guy must have broken some kind of record
LOL. I know right
Closed because it was more than 4 weeks old.
Posts 1–13 of 13 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us