- Get link
- X
- Other Apps
Featured Post
Posted by
Unknown
on
- Get link
- X
- Other Apps
This is a simple password based authentication program which runs both on Windows as well as Linux.
#ifdef __linux__ #include <unistd.h> #endif #include <iostream> #include <stdlib.h> #ifndef __linux__ #include <conio.h> #endif using namespace std; int main() { string pass = ""; #ifdef __linux__ system("clear"); pass = getpass("Enter Password : "); #else system("cls"); char ch; cout << "Enter Password : "; ch = _getch(); while(ch != 13) //character 13 is enter { pass.push_back(ch); cout << '*'; ch = _getch(); } #endif if(pass == "Hello") { cout << "\nAccess granted :P\n"; //Further processing goes here... } else { cout << "\nAccess aborted...\n"; } }
Comments
This looks more like C++ thing...... Why can't we use Char and Array (Pointer) to achieve String and also drop push_back .....
ReplyDeleteYeah you are right. Of course there are many ways to do it. I chose this one.
ReplyDelete