User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » c++ help Page [1]  
hairy_kari
All American
1044 Posts
user info
edit post

Password Verifier - Write a program to verify passwords, satisfying the following specifications:

ALGORITHM:
1. Ask the user to input a possible password.
2. Check to see that it:
- is at least 8 characters long
- is no longer than 16 characters
3. While it's not valid:
- tell the user why it isn't valid
- and go back to step one
4. Once it's valid, ask the user to re-enter it.
5. Compare the new password to the old one, and if it's NOT the same, ask again.
HINT: Could be an inner loop that calls a function.
6. If the user has tried and failed to duplicate the password 3 times, start over, asking for a new password.
7. Once the user has created and verified a good password, give output saying so.

SPECIFICATIONS:
The program should implement the algorithm above.
The program should contain 2 functions other than main that take parameters and return values.
All output statements should belong to main and NOT the other functions.
All calculation and/or comparison statements should exist in other functions - not main.



what kind of loop do I use?

12/4/2005 5:07:44 PM

scud
All American
10804 Posts
user info
edit post

huh?

12/4/2005 5:11:30 PM

State409c
Suspended
19558 Posts
user info
edit post

This is for either your little brother or boyfriend isn't it?

12/4/2005 5:13:38 PM

30thAnnZ
Suspended
31803 Posts
user info
edit post

logical thinking is hard for broads

12/4/2005 5:22:18 PM

hairy_kari
All American
1044 Posts
user info
edit post

Quote :
"logical thinking is hard for broads"

i'm usually good at this kind of shit, but my teacher is really awful.

i'm not asking for someone to write the program for me, just for some direction. i tried using a do-while loop but it won't work. please help me.

12/4/2005 6:02:19 PM

A Tanzarian
drip drip boom
10996 Posts
user info
edit post

Quote :
"tried using a do-while loop "


Try more than one.

12/4/2005 6:41:04 PM

hairy_kari
All American
1044 Posts
user info
edit post

i am stuck on step 3. so far i have a user enter a password which is assigned to a string. i know how to check the string length and make it match the specifications, but i don't know what type of loop to use. i know i will need a for loop for step 6. how do i set up the do-while loop to check the password length?

12/4/2005 6:48:08 PM

moron
All American
34190 Posts
user info
edit post

You can just create an input function, a checkInput function, and an acceptInput function. You read a password, send it to checkInput, if it is bad, tell why, and go back to input, if not, go to acceptInput. That shouldn't really require a loop.

12/4/2005 7:34:39 PM

skokiaan
All American
26447 Posts
user info
edit post

w
t
f


just stick to software engineering

12/4/2005 7:49:35 PM

Novicane
All American
15416 Posts
user info
edit post

can you use "breaks" in c++ like java? if so, just set some breaks in a do-while loop if it meets something or doesn't meet something

12/4/2005 8:03:06 PM

hairy_kari
All American
1044 Posts
user info
edit post

^ i've thought of that but i really just don't know what the fuck i'm doing

thanks for your help everyone; i'm going to go shoot myself now

12/4/2005 8:06:56 PM

r45t4-m4n
All American
629 Posts
user info
edit post

use a CString and use string.getLength() to get length to compare length and string.compare() to compare the 2 strings

when you send it to the function to check its length use a global variable to set if its ok, if its not don't set it (i.e. 0 for OK, 1 for not OK). then in the main use a while loop that depends on that variable

[Edited on December 4, 2005 at 8:50 PM. Reason : ]

12/4/2005 8:44:19 PM

State409c
Suspended
19558 Posts
user info
edit post

this thread needs more pics of your tits

12/4/2005 9:16:04 PM

JaegerNCSU
Veteran
245 Posts
user info
edit post

^ CString is MFC, not standard C++. Use std::string.

12/4/2005 9:17:04 PM

philihp
All American
8349 Posts
user info
edit post

use gotos like this:


goto home;
sweet:
printf("sweet ");
home:
printf("home ");
goto sweet;

12/4/2005 9:30:48 PM

bigben1024
All American
7167 Posts
user info
edit post

there are password check programs online.
hint...
use the "check to see that it..." parts as conditions in your loops.

[Edited on December 4, 2005 at 9:45 PM. Reason : .]

12/4/2005 9:43:43 PM

scud
All American
10804 Posts
user info
edit post

attn: america

please use,
std::basic_string<wchar_t, char_traits<wchar_t>>

12/4/2005 10:15:38 PM

bous
All American
11215 Posts
user info
edit post

OMG LIKE USE

exit(0);

12/4/2005 10:17:42 PM

bigben1024
All American
7167 Posts
user info
edit post

you're biggest favor to yourself would be to not waste your time with the responses of this thread.

12/4/2005 10:20:07 PM

Specter
All American
6575 Posts
user info
edit post

I just wrote this program in C.

12/4/2005 10:36:44 PM

QT4U
All American
557 Posts
user info
edit post

^^^^Unicode is for jews, terrorists, the reds, and pretty much everyone that is bad

UNICODE IS NOT THE AMERICAN WAY

12/4/2005 11:01:21 PM

hairy_kari
All American
1044 Posts
user info
edit post

here is what i have so far:


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

void enterPassword();
void reenterPassword();

string password1;
string password2;
int password1_length;
bool valid_length = false;
bool passwords_match = false;

int main()
{
do
{
cout << "Enter a password: ";
cin >> password1;
enterPassword(); //function call
}
while (valid_length = false);


do
{
cout << "Re-enter your password: ";
cin >> password2;
reenterPassword(); //function call
}
while (passwords_match = false);


system("PAUSE");
return 0;
}


void enterPassword() //function definition
{
password1_length = password1.length();

if ( password1_length >=8 && password1_length <= 16 )
{
valid_length = true;
}

else
{
valid_length = false;
}
}




void reenterPassword() //function definition
{
if ( password1 != password2 )
{
passwords_match = true;
}

else
{
passwords_match = false;
}

}


[Edited on December 5, 2005 at 6:33 PM. Reason : code]

12/5/2005 6:22:26 PM

smoothcrim
Universal Magnetic!
18968 Posts
user info
edit post

I'm pretty sure booleans don't work like that in c++, that's how they work in java. In c++ a 0 is false and anything other than a 0 is not false. There are some other issues like prototyping that I think will break that program (don't you have to include your parameters in a prototype in c++) but yeah.. you shouldn't use globals in the first place, they're considered bad practice.

off the top of my head.. for strings you use strcpr or strcompare or whatever the hell string compare is abbreviated as.

there's.. a lot to work on, maybe grabbing the book would help?

12/5/2005 6:40:38 PM

skokiaan
All American
26447 Posts
user info
edit post

maybe changing majors would help.

[Edited on December 5, 2005 at 7:37 PM. Reason : this is incredibly bad]

12/5/2005 7:37:13 PM

DaveOT
All American
11945 Posts
user info
edit post

^^In C, that's right (0 = false, nonzero = true).

In C++, you can still use numbers (like I tend to), or you can use the boolean types (which I believe are just replaced with the 0/1 designation by the preprocessor).



Actually, I'm out of date. The standard for C now includes a boolean type as well:

http://home.att.net/~jackklein/c/inttypes.html

[Edited on December 5, 2005 at 7:43 PM. Reason : new standard]

12/5/2005 7:40:18 PM

Lowjack
All American
10491 Posts
user info
edit post

I dare you to copy this:


#include <iostream>
#include <string>
using namespace std;

int validPassword(string pw, string *error) {
if(pw.length() < 8 ) {
*error = "Password too short\n";
return 0;
}
if(pw.length() > 16 ) {
*error = "Password too long\n";
return 0;
}
*error = "";
return 1;
}

bool verifyPassword( string pw, string newPw, string *error) {
if(pw.compare(newPw)) {
*error = "Passwords do not match\n";
return false;
}
else {
*error = "";
return true;
}
}

int main (int argc, char * const argv[]) {
string pw = "";
string newPw="";
string error ="";
int verifyCount = 0;
bool verified = false;

while(!verified) {
cout << error;
switch(verifyCount) {
case 0:
cout << "Enter a new password:\n";
cin >> pw;
verifyCount = validPassword(pw, &error);
break;
case 1:
case 2:
case 3:
cout << "Verify password:\n";
cin >> newPw;
verified = verifyPassword(pw, newPw, &error );
verifyCount++;
break;
case 4:
verifyCount = 0;
error = "Could not verify password.\n";
break;
}
}

return 0;
}


[Edited on December 5, 2005 at 10:03 PM. Reason : ps. it's easy for them to tell if you copy obfuscated code]

12/5/2005 9:59:29 PM

gephelps
All American
2369 Posts
user info
edit post

Is there a message board from the class that can narrow some stuff down?

Quote :
"All calculation and/or comparison statements should exist in other functions - not main."

From a glance this requirement would make the assignment a nightmare in the strictest sense, but maybe I'm reading it wrong.

Quote :
" The program should contain 2 functions other than main that take parameters and return values. "

Can you have more than 2 functions or only 2?


From the code you posted:
1) I would expect to recieve a zero for using all the global statements. From the rules you posted:
Quote :
"The program should contain 2 functions other than main that take parameters and return values."
Your functions don't return anything! Fail.

2)
Quote :
"The program should contain 2 functions other than main that take parameters and return values."
For me reading this, by taking parameters I would have the user enter the passowrd in a function, not in main.

Here is a start to a better solution (Assuming you can have more that two functions):
1) Have one function whose sole function is to take in a password. Pass the password back to main.
2) Send the password to a validate length function. Return is the length was good, short, or long.
3) Once you have a good password call #1 again for the second password.
4) Send the two passwords to a password compare function. Return whether they match or not.
5) Either they match within 3 tries or you start from scratch if they don't.
6) If you make it this far print out that the password has been set.

12/5/2005 10:51:50 PM

philihp
All American
8349 Posts
user info
edit post

real men jump directly into other functions, and goto directly out.

12/5/2005 11:19:09 PM

skokiaan
All American
26447 Posts
user info
edit post

damn straight

12/5/2005 11:25:53 PM

gephelps
All American
2369 Posts
user info
edit post

^^ You can try and flex an e-penis all you want, but with what was posted before this person is nowhere close to doing that.

Since I am no where close to being a developer... I would hope one of you would be able to do it better, but yet again that is no help to this person.

We all have our strengths.

12/5/2005 11:29:34 PM

skokiaan
All American
26447 Posts
user info
edit post

recursion!

12/5/2005 11:31:34 PM

hairy_kari
All American
1044 Posts
user info
edit post

I got it to work. thanks to those of you who attempted to help me

12/6/2005 12:05:59 AM

bigben1024
All American
7167 Posts
user info
edit post

post your solution so your classmates can copy.

12/6/2005 2:36:29 AM

philihp
All American
8349 Posts
user info
edit post

post your solution so your classmates can copy.

12/6/2005 5:26:29 AM

 Message Boards » Tech Talk » c++ help Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.