L.SYSTEM

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 16
Reputation: badboizEnt is an unknown quantity at this point 
Solved Threads: 0
badboizEnt badboizEnt is offline Offline
Newbie Poster

L.SYSTEM

 
0
  #1
Apr 14th, 2009
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

  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. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: L.SYSTEM

 
0
  #2
Apr 14th, 2009
Add Password=""; before
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 16
Reputation: badboizEnt is an unknown quantity at this point 
Solved Threads: 0
badboizEnt badboizEnt is offline Offline
Newbie Poster

Re: L.SYSTEM

 
0
  #3
Apr 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: L.SYSTEM

 
0
  #4
Apr 14th, 2009
Try something like this instead of your while(encrypt!=13) loop:
  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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 16
Reputation: badboizEnt is an unknown quantity at this point 
Solved Threads: 0
badboizEnt badboizEnt is offline Offline
Newbie Poster

Re: L.SYSTEM

 
0
  #5
Apr 14th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 16
Reputation: badboizEnt is an unknown quantity at this point 
Solved Threads: 0
badboizEnt badboizEnt is offline Offline
Newbie Poster

Re: L.SYSTEM

 
0
  #6
Apr 14th, 2009
thank you very much. your code came through for me.. you have really been of assistance to me..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC