![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
simple password checker
i created a program that prompts the user to give a psswrd, then the program stores the password. the program then checks the password. but when it gets to the part where it checks the password, no matter what i do, it never sees that the two strings are the same...i was wondering if i someone could point me in the right direction?
anyways, here is the code: //store/check password
#include <iostream>
#include <cstdlib>
using namespace std;
class pswrd {
public:
char ps[80], usr[80];
int len;
void set_ps (char *p) {strcpy(ps, p);}
void check_ps () {
printf("\nPassword: ");
cin>>usr;
if(usr!=ps) cout<<endl<<"Access Denied";
else if(usr==ps) cout<<endl<<"Access Granted";
}
};
int main ()
{
pswrd ob1;
char p[80];
printf("Set Password: ");
cin>>p;
ob1.set_ps(p);
ob1.check_ps();
system("PAUSE");
} |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Try using the strcmp() function.
![]()
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#3 |
|
Professional Programmer
|
Or stop using C headers and functions, seeing as this is posted in the C++ forum, and use std::string.
Then you can use != and == on them. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Oct 2005
Posts: 12
Rep Power: 0
![]() |
You might also want to initialize the strings ps and usr.
|
|
|
|
|
|
#5 | |
|
Professional Programmer
|
Quote:
|
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
@ionexchange: I checked the rules and the one forbidding posting voodoo solutions seems to have disappeared. Please don't do it, anyway.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jan 2006
Posts: 55
Rep Power: 3
![]() |
the reason that i didnt initialize ps and usr, is b/c the program makes it so that the user inputs the password. i made this program just to see if i could..anways, thx everyone for the help. the program works now, and the final source is this:
//store/check password
#include <iostream>
#include <cstdlib>
using namespace std;
class pswrd {
public:
char ps[80], usr[80];
int len;
void set_ps (char *p) {strcpy(ps, p);}
void check_ps () {
printf("\nPassword: ");
cin>>usr;
if(strcmp(usr,ps)) cout<<endl<<"Access Denied";
else if cout<<endl<<"Access Granted";
}
};
int main ()
{
pswrd ob1;
char p[80];
printf("Set Password: ");
cin>>p;
ob1.set_ps(p);
ob1.check_ps();
system("PAUSE");
} |
|
|
|
|
|
#8 | ||
|
Professional Programmer
|
Quote:
Quote:
cpp Syntax (Toggle Plain Text)
EDIT: Too slow, DaWei beat me to it...
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
||
|
|
|
|
|
#9 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#10 |
|
Professional Programmer
|
You're still using C functions and C strings in a C++ program.
And what happens when I come along and enter my 81 character password? Looks like bad news. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnlineTextEditor.Com! | Sane | Show Off Your Open Source Projects | 43 | Jun 16th, 2006 8:55 AM |
| [Python] Password Generator | bulio | Show Off Your Open Source Projects | 2 | Feb 28th, 2006 3:01 AM |
| password box | ragenuub | Visual Basic | 5 | Nov 15th, 2005 3:46 PM |
| Just a small password generator | Jessehk | Show Off Your Open Source Projects | 3 | Sep 16th, 2005 8:41 AM |
| Simple Function Questions | meverha1 | C++ | 16 | Sep 12th, 2005 1:25 AM |