Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string myusername;
- string mypassword;
- bool Access_granted;
- int password_attempts;
- cout << "Enter your username: ";
- cin >> myusername;
- cout << "Enter your password: ";
- cin >> mypassword;
- if (myusername == "veasy62" && mypassword == "a65908") {
- Access_granted = true;
- cout << "Access granted veasy62n";
- }
- else if (myusername == "tveasy62" || mypassword == "a1065908") {
- Access_granted = true;
- cout << "Access granted tveasy62n";
- }
- else {
- Access_granted = false;
- cout << password_attempts;
- cout << "Access Denied, Sorry try againn";
- if (Access_granted == false) {
- if (password_attempts = 2) {
- password_attempts = password_attempts + 1;
- return main();
- }
- else {
- cout << "Sorry you have ran out of attemptsn";
- }
- }
- }
- }
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string myusername;
- string mypassword;
- bool Access_granted;
- int password_attempts=0;
- HERE : cout << "Enter your username: ";
- cin >> myusername;
- cout << "Enter your password: ";
- cin >> mypassword;
- if (myusername == "veasy62" && mypassword == "a65908") {
- Access_granted = true;
- cout << "Access granted veasy62n";
- break;
- }
- else if (myusername == "tveasy62" && mypassword == "a1065908") {
- Access_granted = true;
- cout << "Access granted tveasy62n";
- break;
- }
- else {
- password_attempts = password_attempts + 1;
- Access_granted = false;
- cout << password_attempts;
- cout << "Access Denied, Sorry try againn";
- if (password_attempts == 2) {
- cout << "Sorry you have ran out of attemptsn";
- return 0;
- //to exit main().can also use exit(0) using additional libraries
- }
- else{
- goto HERE;
- }
- }
- }
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string myusername;
- string mypassword;
- bool Access_granted;
- int password_attempts=0;
- restart:
- cout << "Enter your username: ";
- cin >> myusername;
- cout << "Enter your password: ";
- cin >> mypassword;
- if(myusername == "veasy62" && mypassword == "12")
- {
- Access_granted = true;
- cout<<"Access granted veasy62" << endl;
- }
- else if (myusername == "tveasy62" || mypassword == "a1065908" )
- {
- Access_granted = true;
- cout<<"Access granted tveasy62" << endl;
- }
- else
- {
- Access_granted = false;
- if(Access_granted == false)
- {
- if(password_attempts < 2 )
- {
- cout << "Access Denied, Sorry try again" << endl;
- password_attempts = password_attempts + 1;
- cout << "you have remaining " << 2-password_attempts << " time chances after this attempt" << endl;
- goto restart;
- }
- else
- {
- cout << "Sorry you have ran out of attemptsn";
- }
- }
- }
- return 0;
- }
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string myusername;
- string mypassword;
- bool Access_granted;
- int password_attempts=0;
- cout << "Enter your username: ";
- cin >> myusername;
- cout << "Enter your password: ";
- cin >> mypassword;
- if (myusername == "veasy62" && mypassword == "a65908") {
- Access_granted = true;
- cout << "Access granted veasy62n";
- }
- else if (myusername == "tveasy62" || mypassword == "a1065908") {
- Access_granted = true;
- cout << "Access granted tveasy62n";
- system("pause");
- return 0;
- }
- else {
- Access_granted = false;
- cout << "Access Denied, Sorry try againn";
- cout << "Enter your username: ";
- cin >> myusername;
- cout << "Enter your password: ";
- cin >> mypassword;
- if (myusername == "veasy62" && mypassword == "a65908") {
- Access_granted = true;
- cout << "Access granted veasy62n";
- }
- else if (myusername == "tveasy62" || mypassword == "a1065908") {
- Access_granted = true;
- cout << "Access granted tveasy62n";
- system("pause");
- return 0;
- }
- else
- {
- cout << "Sorry you have ran out of attemptsn";
- cout << "Access Denied";
- system("pause");
- return -1;
- }
- }
- return 0;
- }
- #include <string>
- #include <iostream>
- template <int attempts>
- struct password_entry
- {
- password_entry(std::string& myusername, std::string& mypassword, bool& Access_granted)
- {
- std::cout << "Enter your username: ";
- std::cin >> myusername;
- std::cout << "Enter your password: ";
- std::cin >> mypassword;
- Access_granted = true;
- if (myusername == "veasy62" && mypassword == "12")
- std::cout << "Access granted veasy62" << std::endl;
- else
- {
- if ( attempts > 1 )
- std::cout << "Access denied. You have " << attempts - 1 << " attempts remainingn";
- password_entry<attempts - 1>(myusername, mypassword, Access_granted);
- }
- }
- };
- // specialization when attempts have run out
- template <>
- struct password_entry<0>
- {
- password_entry(const std::string&, const std::string& ,
- bool& Access_granted)
- {
- std::cout << "Sorry you have ran out of attemptsn";
- Access_granted = false;
- }
- };
- int main()
- {
- std::string mypass, myuser;
- bool access_granted;
- // max 2 attempts
- password_entry<2>(myuser, mypass, access_granted);
- if ( access_granted )
- std::cout << "Welcome current user";
- else
- std::cout << "Please call 555-5555 to reset your password";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement