Okay...I've been trying to write a piece of code to read a password from the keyboard, check it against a static password (or set thereof; I've found that if I put more than one password in the text file that I'm using currently, the "correct" password cycles depending on what try the user is on). I've gotten far enough to have the code work, but with more than one logic error, and I am confuzzled as to how I go about getting around that. The logic errors plaguing this piece of code are simple: if the password is entered incorrectly multiple times, then when it is finally entered correctly the API is completely ignored, as though I never put it in. I believe the way that I originally referenced the strings to be partially responsible for this, as I originally had it checking whole words against one another instead of what I believe to be the added redundancy of having the checker loop compare individual characters.
My problem is that I am as of yet unsure of whether my strings (pass and passcheck) will accept being indexed as if they were arrays, which is essential to the correct operation of my program.
This originally started off as a homework assignment, but has grown into something of a side project of mine. Any assistance you can provide would be most appreciated (any day I can stave off a headache is a good day indeed).
Code:
#include <conio.h>
#include <fstream.h>
#include <string>
#include <c:\\bc5\\include\\win32\\windows.h>
#include <ctype.h>
void func(char* (&array)[11]) /*passes array by reference; I had an idea from searching around, and was going to try to modify this function to do my bidding*/
{
for (int i = 0; i < 11; ++i)
{
cout << array[i] << '\n';
}
}
/*void main()*/
int main()
{
fstream password("passwd.txt",ios::in);
string pass,passcheck;
cout<<"Enter your password: ";
cin<<pass;
/*do*/
/*while(!password.eof)*/
while(password>>passcheck)
{
password>>passcheck;
/*if(pass==passcheck) Old method of checking the password; it checked the values of whole words against one another rather than individual letters
{
MessageBox(0,"Accepted", "Ok", MB_OK|MB_EXCLAMATION|MB_TOPMOST); This is to happen if the password is accepted
else This is to happen if it doesn't
{
MessageBox(0,"Access Denied", "Ok", MB_OK|MB_EXCLAMATION|MB_TOPMOST);
}*/
for(i=0;i<11;i++) /*This is my current idea on how to make this program work correctly*/
{
if(pass[i]==passcheck[1]) /*This loop is supposed to check the value assigned to pass[i] against the value assigned to passcheck[i], and if they are equal then continue*/
{
MessageBox(0,"Accepted","Ok",MB_OK|MB_EXCLAMATION|MB_TOPMOST);
}
}
/*while(!password.eof)*/ /*I never really could get that particular piece of syntax to work correctly, so I gave up and wrote the above while loop*/
return 0;
}
Bookmarks