943,752 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1262
  • C++ RSS
Apr 14th, 2009
0

L.SYSTEM

Expand Post »
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)
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10.  
  11. string Username;
  12. string Password;
  13. int terminator = 0, terminate = 0;
  14.  
  15. char encrypt;
  16.  
  17. while (terminate < 2)
  18. {
  19. cout << "Username: ";
  20. getline(std::cin, Username);
  21. if (Username == "Raymond")
  22.  
  23. {
  24. terminate = terminate + 3;
  25.  
  26. while (terminator < 2)
  27. {
  28. cout << "Password: ";
  29. encrypt = _getch();
  30.  
  31.  
  32. while(encrypt != 13)
  33.  
  34. {
  35. Password.push_back(encrypt);
  36. cout << '*';
  37. encrypt = _getch();
  38. }
  39.  
  40. if (Password == "123456")
  41. {
  42. cout << "\n Welcome Raymond.... \n ";
  43. terminator = terminator + 3;
  44. }
  45.  
  46. else
  47. {
  48. cout << "invalid password. Please enter valid password." << std::endl;
  49. cout << "\a\n";
  50. terminator = terminator + 1;
  51. }
  52. }
  53.  
  54. } else {
  55. cout << "invalid username. Please enter valid username." << std::endl;
  56. cout << "\a\n";
  57. terminate = terminate + 1;
  58. }
  59. }
  60.  
  61.  
  62. return 0;
  63. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
badboizEnt is offline Offline
18 posts
since Mar 2009
Apr 14th, 2009
0

Re: L.SYSTEM

Add Password=""; before
c++ Syntax (Toggle Plain Text)
  1. while(encrypt != 13)
  2.  
  3. {
  4. Password.push_back(encrypt);
  5. cout << '*';
  6. encrypt = _getch();
  7. }

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.
Reputation Points: 42
Solved Threads: 13
Junior Poster in Training
unbeatable0 is offline Offline
90 posts
since Sep 2008
Apr 14th, 2009
0

Re: L.SYSTEM

thankss very much dont no how too thank you. but i need a final solution to my problem of the backspce key inputtting as a character... please i would be very grateful if my request could be checked out. cheers
Reputation Points: 10
Solved Threads: 0
Newbie Poster
badboizEnt is offline Offline
18 posts
since Mar 2009
Apr 14th, 2009
0

Re: L.SYSTEM

Try something like this instead of your while(encrypt!=13) loop:
c++ Syntax (Toggle Plain Text)
  1. while(encrypt != 13)
  2. {
  3. if(encrypt!='\b')
  4. {
  5. Password.push_back(encrypt);
  6. cout << '*';
  7. }
  8. else if(Password.length()>0) // Backspace only when possible
  9. {
  10. Password.resize(Password.length()-1); // Will also erase the last character
  11. cout<<"\b \b"; // Inserts a space in place of the previous asterisk and moves to the desired location
  12. }
  13.  
  14. encrypt = _getch();
  15. }
Last edited by unbeatable0; Apr 14th, 2009 at 9:45 am.
Reputation Points: 42
Solved Threads: 13
Junior Poster in Training
unbeatable0 is offline Offline
90 posts
since Sep 2008
Apr 14th, 2009
0

Re: L.SYSTEM

thanks very much, but it still has a problem the backspace deletes a character, but cant delete a second and the program freezes. is there anything that can be done to resolve this? i really appreciate your responses. thank you so much, so sorry if am being persistent
Reputation Points: 10
Solved Threads: 0
Newbie Poster
badboizEnt is offline Offline
18 posts
since Mar 2009
Apr 14th, 2009
0

Re: L.SYSTEM

thank you very much. your code came through for me.. you have really been of assistance to me..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
badboizEnt is offline Offline
18 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Weird fstream problem when access member of a object inside other class..
Next Thread in C++ Forum Timeline: Intermediate Permutation...?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC