Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9. string myusername;
  10. string mypassword;
  11. bool Access_granted;
  12. int password_attempts;
  13. cout << "Enter your username: ";
  14. cin >> myusername;
  15. cout << "Enter your password: ";
  16. cin >> mypassword;
  17. if (myusername == "veasy62" && mypassword == "a65908") {
  18. Access_granted = true;
  19. cout << "Access granted veasy62n";
  20. }
  21. else if (myusername == "tveasy62" || mypassword == "a1065908") {
  22. Access_granted = true;
  23. cout << "Access granted tveasy62n";
  24. }
  25. else {
  26. Access_granted = false;
  27. cout << password_attempts;
  28. cout << "Access Denied, Sorry try againn";
  29. if (Access_granted == false) {
  30. if (password_attempts = 2) {
  31. password_attempts = password_attempts + 1;
  32. return main();
  33. }
  34. else {
  35. cout << "Sorry you have ran out of attemptsn";
  36. }
  37. }
  38. }
  39. }
  40.  
  41. #include <iostream>
  42. #include <string>
  43.  
  44. using namespace std;
  45.  
  46. int main()
  47. {
  48.  
  49. string myusername;
  50. string mypassword;
  51. bool Access_granted;
  52. int password_attempts=0;
  53.  
  54. HERE : cout << "Enter your username: ";
  55. cin >> myusername;
  56. cout << "Enter your password: ";
  57. cin >> mypassword;
  58. if (myusername == "veasy62" && mypassword == "a65908") {
  59. Access_granted = true;
  60. cout << "Access granted veasy62n";
  61. break;
  62. }
  63. else if (myusername == "tveasy62" && mypassword == "a1065908") {
  64. Access_granted = true;
  65. cout << "Access granted tveasy62n";
  66. break;
  67. }
  68. else {
  69. password_attempts = password_attempts + 1;
  70. Access_granted = false;
  71. cout << password_attempts;
  72. cout << "Access Denied, Sorry try againn";
  73.  
  74. if (password_attempts == 2) {
  75. cout << "Sorry you have ran out of attemptsn";
  76. return 0;
  77.  
  78. //to exit main().can also use exit(0) using additional libraries
  79. }
  80. else{
  81. goto HERE;
  82. }
  83. }
  84.  
  85. }
  86.  
  87. #include <iostream>
  88. #include <string>
  89. using namespace std;
  90.  
  91. int main()
  92. {
  93. string myusername;
  94. string mypassword;
  95. bool Access_granted;
  96. int password_attempts=0;
  97. restart:
  98. cout << "Enter your username: ";
  99. cin >> myusername;
  100. cout << "Enter your password: ";
  101. cin >> mypassword;
  102. if(myusername == "veasy62" && mypassword == "12")
  103. {
  104. Access_granted = true;
  105. cout<<"Access granted veasy62" << endl;
  106. }
  107. else if (myusername == "tveasy62" || mypassword == "a1065908" )
  108. {
  109. Access_granted = true;
  110. cout<<"Access granted tveasy62" << endl;
  111. }
  112. else
  113. {
  114. Access_granted = false;
  115.  
  116.  
  117. if(Access_granted == false)
  118. {
  119. if(password_attempts < 2 )
  120. {
  121. cout << "Access Denied, Sorry try again" << endl;
  122. password_attempts = password_attempts + 1;
  123. cout << "you have remaining " << 2-password_attempts << " time chances after this attempt" << endl;
  124. goto restart;
  125. }
  126. else
  127. {
  128. cout << "Sorry you have ran out of attemptsn";
  129. }
  130. }
  131. }
  132.  
  133. return 0;
  134. }
  135.  
  136. #include <iostream>
  137. #include <string>
  138.  
  139. using namespace std;
  140.  
  141. int main()
  142. {
  143.  
  144. string myusername;
  145. string mypassword;
  146. bool Access_granted;
  147. int password_attempts=0;
  148.  
  149.  
  150.  
  151.  
  152. cout << "Enter your username: ";
  153. cin >> myusername;
  154. cout << "Enter your password: ";
  155. cin >> mypassword;
  156. if (myusername == "veasy62" && mypassword == "a65908") {
  157. Access_granted = true;
  158. cout << "Access granted veasy62n";
  159. }
  160. else if (myusername == "tveasy62" || mypassword == "a1065908") {
  161. Access_granted = true;
  162. cout << "Access granted tveasy62n";
  163. system("pause");
  164. return 0;
  165. }
  166. else {
  167. Access_granted = false;
  168. cout << "Access Denied, Sorry try againn";
  169. cout << "Enter your username: ";
  170. cin >> myusername;
  171. cout << "Enter your password: ";
  172. cin >> mypassword;
  173. if (myusername == "veasy62" && mypassword == "a65908") {
  174. Access_granted = true;
  175. cout << "Access granted veasy62n";
  176. }
  177. else if (myusername == "tveasy62" || mypassword == "a1065908") {
  178. Access_granted = true;
  179. cout << "Access granted tveasy62n";
  180. system("pause");
  181. return 0;
  182. }
  183. else
  184. {
  185.  
  186.  
  187. cout << "Sorry you have ran out of attemptsn";
  188. cout << "Access Denied";
  189. system("pause");
  190. return -1;
  191. }
  192. }
  193.  
  194.  
  195.  
  196. return 0;
  197. }
  198.  
  199. #include <string>
  200. #include <iostream>
  201.  
  202. template <int attempts>
  203. struct password_entry
  204. {
  205. password_entry(std::string& myusername, std::string& mypassword, bool& Access_granted)
  206. {
  207. std::cout << "Enter your username: ";
  208. std::cin >> myusername;
  209. std::cout << "Enter your password: ";
  210. std::cin >> mypassword;
  211. Access_granted = true;
  212. if (myusername == "veasy62" && mypassword == "12")
  213. std::cout << "Access granted veasy62" << std::endl;
  214. else
  215. {
  216. if ( attempts > 1 )
  217. std::cout << "Access denied. You have " << attempts - 1 << " attempts remainingn";
  218. password_entry<attempts - 1>(myusername, mypassword, Access_granted);
  219. }
  220. }
  221. };
  222.  
  223. // specialization when attempts have run out
  224. template <>
  225. struct password_entry<0>
  226. {
  227. password_entry(const std::string&, const std::string& ,
  228. bool& Access_granted)
  229. {
  230. std::cout << "Sorry you have ran out of attemptsn";
  231. Access_granted = false;
  232. }
  233. };
  234.  
  235. int main()
  236. {
  237. std::string mypass, myuser;
  238. bool access_granted;
  239.  
  240. // max 2 attempts
  241. password_entry<2>(myuser, mypass, access_granted);
  242. if ( access_granted )
  243. std::cout << "Welcome current user";
  244. else
  245. std::cout << "Please call 555-5555 to reset your password";
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement