| | |
L.SYSTEM
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2009
Posts: 16
Reputation:
Solved Threads: 0
please i need help with my code below, when ever i enter a wrond password first it gives me an error which its suppose to, but when entering the correct code next it still gives me an error message. could someone help me counter this problem. cheers
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <string> #include <conio.h> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string Username; string Password; int terminator = 0, terminate = 0; char encrypt; while (terminate < 2) { cout << "Username: "; getline(std::cin, Username); if (Username == "Raymond") { terminate = terminate + 3; while (terminator < 2) { cout << "Password: "; encrypt = _getch(); while(encrypt != 13) { Password.push_back(encrypt); cout << '*'; encrypt = _getch(); } if (Password == "123456") { cout << "\n Welcome Raymond.... \n "; terminator = terminator + 3; } else { cout << "invalid password. Please enter valid password." << std::endl; cout << "\a\n"; terminator = terminator + 1; } } } else { cout << "invalid username. Please enter valid username." << std::endl; cout << "\a\n"; terminate = terminate + 1; } } return 0; }
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
Add
That's because when the user enters a wrong password you keep
Password=""; before c++ Syntax (Toggle Plain Text)
while(encrypt != 13) { Password.push_back(encrypt); cout << '*'; encrypt = _getch(); }
That's because when the user enters a wrong password you keep
Password with the wrong password and just add characters to it. You need to empty it before. Last edited by unbeatable0; Apr 14th, 2009 at 8:36 am.
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
Try something like this instead of your
while(encrypt!=13) loop: c++ Syntax (Toggle Plain Text)
while(encrypt != 13) { if(encrypt!='\b') { Password.push_back(encrypt); cout << '*'; } else if(Password.length()>0) // Backspace only when possible { Password.resize(Password.length()-1); // Will also erase the last character cout<<"\b \b"; // Inserts a space in place of the previous asterisk and moves to the desired location } encrypt = _getch(); }
Last edited by unbeatable0; Apr 14th, 2009 at 9:45 am.
![]() |
Similar Threads
- Wanted: System/Network administrator. all levels (Tech / IT Consultant Job Offers)
- Exciting Senior Windows System Administrator (Tech / IT Consultant Job Offers)
- Error Loading operating System (Windows NT / 2000 / XP)
- SYSTEM.INI missing on WIN 98 SE (Windows 95 / 98 / Me)
- system registry missing, Missing system.ini (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Weird fstream problem when access member of a object inside other class..
- Next Thread: Intermediate Permutation...?
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





