LOGIN

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

LOGIN

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

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: LOGIN

 
0
  #2
Apr 10th, 2009
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.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: LOGIN

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

Re: LOGIN

 
0
  #4
Apr 10th, 2009
It will better for the program if the username and password is defined by the user itself..
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