Need a little help with password code

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

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

Need a little help with password code

 
0
  #1
Apr 24th, 2005
Well I got the password code right, I think.
I have a few problems
1) it wont close properly
2) Can someone point me in the right direction to find a tutorial that teach me how to only let the user have 34 tries before it close and also to encrypt the password to a file then decrypt it and compare it to another file that contain the correct password( I think that it use the fstream but I dont know the decrpytion, encryption, compare part )?
Thank you
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6. int takingPass();
  7. int i;
  8. int pass1;
  9. char destination[13];
  10. int main()
  11. {
  12.  
  13. cout << "I'm going to kill your computer if you dont enter the right password!!!"<< endl;
  14.  
  15. for (i=0; i<13; i++) //user can input max 13 character
  16. {
  17. destination[i] = getch();
  18. cout << "*";
  19. if (destination[i]==13)
  20. {
  21. takingPass();
  22. }
  23. }
  24. }
  25.  
  26. int takingPass()
  27. {
  28. destination[i] = 0;
  29. pass1 = stricmp(destination,"lovebug"); //compare with name "lovebug"
  30. if (pass1 == 0) // case insensitive
  31. {
  32. cout <<"\nPASSWORD IS CORRECT \n";
  33. }
  34. else //if password is not correct
  35. {
  36. cin.clear(); // clear cin
  37.  
  38. cout <<"\nPASSWORD WAS INCORRECT\n";
  39. main(); //go to main to do until success
  40. }
  41. return 0; // exit program
  42.  
  43. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Need a little help with password code

 
0
  #2
Apr 24th, 2005
>"I'm going to kill your computer if you dont enter the right password!!!"
Uh huh.

>main(); //go to main to do until success
It's illegal to call main recursively in C++.

>teach me how to only let the user have 34 tries before it close
  1. // Pseudo-C++
  2. int n = 0;
  3.  
  4. while ( n < 34 ) {
  5. if ( is_right_password() )
  6. break;
  7. ++n;
  8. }
  9.  
  10. if ( n == 34 )
  11. exit ( EXIT_FAILURE );
  12.  
  13. // Do stuff for correct password
>encrypt the password to a file then decrypt it and compare it to
>another file that contain the correct password
Do you know how to read from a file? If not then it would be best to consult your C++ book (you do have one, right?). The encrypting and decrypting part is a little more difficult depending on your needs, but we'll get to that once you have a program that works with plain text. Those are easier to test for correctness.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 16
Reputation: Tetsu is an unknown quantity at this point 
Solved Threads: 0
Tetsu Tetsu is offline Offline
Newbie Poster

Re: Need a little help with password code

 
0
  #3
Apr 30th, 2005
>"I'm going to kill your computer if you dont enter the right password!!!"
--- well it made me laugh a little. I change some of the wording.

Okay I think I few some of the bugs but I dont know if the program is good.
I got it to save the password a file call out.

  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <conio.h>
  5. #include <stdio.h>
  6. using namespace std;
  7.  
  8. int takingPass();
  9. int o = 0;
  10. int i;
  11. int pass1;
  12. char ch[13];
  13. int wrong();
  14. int main()
  15. {
  16.  
  17.  
  18. ofstream out;
  19. out.open("c:\\out.txt");
  20.  
  21. cout << "Please enter the correct password."<< endl;
  22.  
  23. for (i=0; i<13; i++) //user can input max 13 character
  24. {
  25.  
  26. ch[i] = getch();
  27. cout << "*";
  28. out << ch[i];
  29.  
  30.  
  31.  
  32. if (ch[i]==13)
  33. {
  34. takingPass();
  35. cout << o;
  36. }
  37.  
  38. }
  39.  
  40. out.close();
  41. }
  42.  
  43. int takingPass()
  44. {
  45.  
  46. ch[i] = 0;
  47. o++;
  48. pass1 = stricmp(ch,"lovebug");
  49.  
  50. if (pass1 == 0)
  51. {
  52. cout <<"\nPASSWORD IS CORRECT \n";
  53. exit(1); // exit program if successful
  54. }
  55. else
  56. {
  57. system("cls");
  58. cout <<"PASSWORD WAS INCORRECT\nPLEASE RE-ENTER PASSWORD"<<endl;
  59. cout << "Number of re-tries: "<<o; // show o increasing
  60. cout<< endl;
  61. }
  62. if (o == 3)
  63. {
  64. cout << "YOU ARE A UNAUTHORIZE USER\n";
  65. exit(1); // exit program
  66. }
  67. main();
  68. return 0;
  69.  
  70. }
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC