Thursday, 27 October 2016

simple password based authentication program in c++

#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";
    }
}

No comments:

Post a Comment