943,773 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 371
  • C++ RSS
Apr 10th, 2009
0

LOGIN

Expand Post »
please i was wondering if anyone could help me with my code, i feel its kinda too long and a good program should be as brief as possible... please would be very grateful. appreciated, cheers..

C++ Syntax (Toggle Plain Text)
  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3. string Username;
  4. string Password;
  5. int terminator = 0, terminate = 0;
  6. char encrypt;
  7.  
  8. while (terminate < 2)
  9. {
  10. cout << "Enter Username: ";
  11. getline(std::cin, Username);
  12. if (Username == "Raymond")
  13.  
  14. {
  15. terminate = terminate + 3;
  16.  
  17. while (terminator < 2) {
  18. cout << "\nEnter Password: ";
  19. encrypt = _getch();
  20.  
  21.  
  22. while(encrypt != 13)
  23.  
  24. {
  25. Password.push_back(encrypt);
  26. cout << '*';
  27. encrypt = _getch();
  28. }
  29.  
  30. if (Password == "123456")
  31. {
  32. cout <<"\n\n\t\t******************************";
  33. cout << "\n\t\t* *";
  34. cout << "\n\t\t* *";
  35. cout << "\n\t\t* Welcome Raymond * ";
  36. cout << "\n\t\t* *";
  37. cout <<"\n\t\t******************************"<< endl<<endl ;
  38. terminator = terminator + 3;
  39. }
  40.  
  41. else
  42. {
  43. cout << "\nInvalid password. Please enter valid password." << std::endl;
  44. cout << "\a\n";
  45. terminator = terminator + 1;
  46. }
  47. }
  48.  
  49. } else {
  50. cout << "Invalid username. Please enter valid username." << std::endl;
  51. cout << "\a\n";
  52. terminate = terminate + 1;
  53. }
  54. }
  55.  
  56.  
  57. return 0;
  58.  
  59. }
Last edited by Narue; Apr 10th, 2009 at 11:42 am. Reason: fixed code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
badboizEnt is offline Offline
18 posts
since Mar 2009
Apr 10th, 2009
0

Re: LOGIN

Why are you hard coding the username and password in the code, if you want to improve your login system (make it more universal) you could make an account database where the username and password are stored in ...

Edit:: You could also use a bool called 'terminate', and you let your while run like this while(!terminate) ...
Edit:: It's also a bad security practice when you're notifying the user when a username doesn't exist, it would be better if you ask the user to enter a username and a password, and when one of these is wrong you simply notify the user with "Wrong username or password" ...
Last edited by tux4life; Apr 10th, 2009 at 12:01 pm.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Apr 10th, 2009
0

Re: LOGIN

It would also be nice if it worked. Did you test it fully? Try entering an incorrect password followed by the correct password.

Also, terminate and terminator are confusing names. How about triesUsername and triesPassword ?
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Apr 10th, 2009
0

Re: LOGIN

It will better for the program if the username and password is defined by the user itself..
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008

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: get rid of the punctuations function
Next Thread in C++ Forum Timeline: Databasing problem





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


Follow us on Twitter


© 2011 DaniWeb® LLC