Advertisement
skb50bd

Implement Username & Password in your Code B|

Aug 22nd, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void InputPassword(string &pass) {
  9.     char key;
  10.  
  11.     do{
  12.         key = getch();
  13.  
  14.         switch (key) {
  15.             case '\b':
  16.                 if(pass.length() > 0) {
  17.                     pass.erase(pass.length() - 1, 1);
  18.                     cout << '\b' << " " << '\b';
  19.                 }
  20.                 break;
  21.  
  22.             default:
  23.                 if(key > 31 && key < 127) {
  24.                     pass.push_back(key);
  25.                     cout << "*";
  26.                 }
  27.         }
  28.     }
  29.     while(key != '\r');
  30. }
  31.  
  32.  
  33. int main(){
  34.  
  35.     string pass = "";
  36.     string user = "";
  37.     char ch;
  38.  
  39.     cout << "Enter Username: ";
  40.     cin >> user;
  41.     cout << "Enter Password: ";
  42.     InputPassword(pass);
  43.  
  44.     if(user == "admin" && pass == "admin")
  45.         cout << "\nAccess Granted :P\n";
  46.  
  47.     else
  48.         cout << "\nAccess Denied...\n";
  49.  
  50.     pass = "";
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement