| | |
Need a little help with password code
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 16
Reputation:
Solved Threads: 0
Well I got the password code right, I think.
I have a few problems
1) it wont close properly
2) Can someone point me in the right direction to find a tutorial that teach me how to only let the user have 34 tries before it close and also to encrypt the password to a file then decrypt it and compare it to another file that contain the correct password( I think that it use the fstream but I dont know the decrpytion, encryption, compare part )?
Thank you
I have a few problems
1) it wont close properly
2) Can someone point me in the right direction to find a tutorial that teach me how to only let the user have 34 tries before it close and also to encrypt the password to a file then decrypt it and compare it to another file that contain the correct password( I think that it use the fstream but I dont know the decrpytion, encryption, compare part )?
Thank you
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> #include <conio.h> using namespace std; int takingPass(); int i; int pass1; char destination[13]; int main() { cout << "I'm going to kill your computer if you dont enter the right password!!!"<< endl; for (i=0; i<13; i++) //user can input max 13 character { destination[i] = getch(); cout << "*"; if (destination[i]==13) { takingPass(); } } } int takingPass() { destination[i] = 0; pass1 = stricmp(destination,"lovebug"); //compare with name "lovebug" if (pass1 == 0) // case insensitive { cout <<"\nPASSWORD IS CORRECT \n"; } else //if password is not correct { cin.clear(); // clear cin cout <<"\nPASSWORD WAS INCORRECT\n"; main(); //go to main to do until success } return 0; // exit program }
>"I'm going to kill your computer if you dont enter the right password!!!"
Uh huh.
>main(); //go to main to do until success
It's illegal to call main recursively in C++.
>teach me how to only let the user have 34 tries before it close
>encrypt the password to a file then decrypt it and compare it to
>another file that contain the correct password
Do you know how to read from a file? If not then it would be best to consult your C++ book (you do have one, right?). The encrypting and decrypting part is a little more difficult depending on your needs, but we'll get to that once you have a program that works with plain text. Those are easier to test for correctness.
Uh huh.
>main(); //go to main to do until success
It's illegal to call main recursively in C++.
>teach me how to only let the user have 34 tries before it close
C++ Syntax (Toggle Plain Text)
// Pseudo-C++ int n = 0; while ( n < 34 ) { if ( is_right_password() ) break; ++n; } if ( n == 34 ) exit ( EXIT_FAILURE ); // Do stuff for correct password
>another file that contain the correct password
Do you know how to read from a file? If not then it would be best to consult your C++ book (you do have one, right?). The encrypting and decrypting part is a little more difficult depending on your needs, but we'll get to that once you have a program that works with plain text. Those are easier to test for correctness.
I'm here to prove you wrong.
•
•
Join Date: Mar 2005
Posts: 16
Reputation:
Solved Threads: 0
>"I'm going to kill your computer if you dont enter the right password!!!"
--- well it made me laugh a little. I change some of the wording.
Okay I think I few some of the bugs but I dont know if the program is good.
I got it to save the password a file call out.
--- well it made me laugh a little. I change some of the wording.
Okay I think I few some of the bugs but I dont know if the program is good.
I got it to save the password a file call out.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> #include <conio.h> #include <stdio.h> using namespace std; int takingPass(); int o = 0; int i; int pass1; char ch[13]; int wrong(); int main() { ofstream out; out.open("c:\\out.txt"); cout << "Please enter the correct password."<< endl; for (i=0; i<13; i++) //user can input max 13 character { ch[i] = getch(); cout << "*"; out << ch[i]; if (ch[i]==13) { takingPass(); cout << o; } } out.close(); } int takingPass() { ch[i] = 0; o++; pass1 = stricmp(ch,"lovebug"); if (pass1 == 0) { cout <<"\nPASSWORD IS CORRECT \n"; exit(1); // exit program if successful } else { system("cls"); cout <<"PASSWORD WAS INCORRECT\nPLEASE RE-ENTER PASSWORD"<<endl; cout << "Number of re-tries: "<<o; // show o increasing cout<< endl; } if (o == 3) { cout << "YOU ARE A UNAUTHORIZE USER\n"; exit(1); // exit program } main(); return 0; }
![]() |
Similar Threads
- Verifying Username/Password...Please wait. (ASP)
- password protecting (HTML and CSS)
- Need help to encrypt and decrypt password in VB (Visual Basic 4 / 5 / 6)
- source code security (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: Using Vectors and Arrays with fstream
- Next Thread: Help Need Urgently - C++ Gui
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






