Featured Post

Trie implementation in C

Simple password based authentication program in C

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

  1. This looks more like C++ thing...... Why can't we use Char and Array (Pointer) to achieve String and also drop push_back .....

    ReplyDelete
  2. Yeah you are right. Of course there are many ways to do it. I chose this one.

    ReplyDelete

Post a Comment

Please post your valuable suggestions