#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <curses.h>

WINDOW * wnd;
char ch=0;
char pwd[22];
int n=0,p=4;

main(int argc,char ** argv)
        {
        signal(SIGQUIT,SIG_IGN);
        signal(SIGINT,SIG_IGN);
        signal(SIGTERM,SIG_IGN);
        signal(SIGTSTP,SIG_IGN);
        if(argc<2)
                return fprintf(stderr,"Usage: %s <PASSWORD>\n",argv[0]);
        initscr();
        cbreak();
        noecho();
        if((wnd=newwin(5,30,8,25))==NULL)
                {
                endwin();
                return 22;
                };
        intrflush(stdscr,FALSE);
        printw("\t This terminal is LOCKED by \"%s\" . To unlock input password !",getlogin());
        refresh();
        while(1)
                {
                memset(pwd,0,sizeof(pwd));
                p=4;n=0;
                wclear(wnd);
                wrefresh(wnd);
                box(wnd,0,0);
                mvwprintw(wnd,0,8," [ Password ] ");
                mvwprintw(wnd,3,3,"[......................]");
                wmove(wnd,3,4);
                wrefresh(wnd);
                while(1)
                        {
                        ch=wgetch(wnd);
                        if((ch==27)||(ch==8))
                                {
                                if(ch==27)
                                        ch=wgetch(wnd);
                                if (ch==91)
                                        ch=wgetch(wnd);
                                if((n>0)&((ch==68)||(ch==8)))
                                        {
                                        n--;pwd[n]=0;p--;
                                        mvwprintw(wnd,3,p,".");
                                        };
                                continue;
                                };
                        if(ch==10)
                                break;
                        mvwprintw(wnd,3,p,"*");
                        pwd[n]=ch;
                        n++;p++;
                        };
                if(!strcmp(argv[1],pwd))
                        {
                        delwin(wnd);
                        endwin();
                        return 0;
                        };
                flushinp();
                };
        };
