unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, Mask, ExtCtrls, CtrlAltDel, jpeg, TFlatButtonUnit,
  TFlatEditUnit;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Panel2: TPanel;
    Label2: TLabel;
    CtrlAltDel1: TCtrlAltDel;
    Image1: TImage;
    MEdPassw: TFlatEdit;
    Button2: TFlatButton;
    procedure FormShow(Sender: TObject);
    procedure hideTaskbar;
    procedure showTaskbar;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

//Define the password, you can also specify password from the registry
//or an ini-file.  This is the easiest way ...
Const
  Password = 'packardbell';

var
  Form1: TForm1;
  CloseIsOK : Boolean;
  Counter : Integer;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
begin
  //Disables Ctrl + Alt + Del
  CtrlAltDel1.Active := True;
  //Hides the taskbar
  HideTaskBar;
  //Makes the form cover the whole screen
  Form1.Width  := Screen.Width+2;
  Form1.Height := Screen.Height+2;
  //Positions the panel at the screen center
  Panel1.Top := (Form1.Height-Panel1.Height) div 2;
  Panel1.Left := (Form1.Width-Panel1.Width) div 2;
  //Initialize our counter variable.
  Counter := 0;
  CloseIsOK := False;
end;

//This procedure hides the taskbar
procedure TForm1.hideTaskbar;
var wndHandle : THandle;
     wndClass  : array[0..50] of Char;
begin
  StrPCopy(@wndClass[0], 'Shell_TrayWnd');
  wndHandle := FindWindow(@wndClass[0], nil);
  ShowWindow(wndHandle, SW_HIDE);
end;

//This procedure shows the taskbar again
procedure TForm1.showTaskbar;
var wndHandle : THandle;
    wndClass  : array[0..50] of Char;
begin
  StrPCopy(@wndClass[0], 'Shell_TrayWnd');
  wndHandle := FindWindow(@wndClass[0], nil);
  ShowWindow(wndHandle, SW_RESTORE);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   //Enables Ctrl + Alt + Del
   CtrlAltDel1.Active := False;
  //Make sure that the taskbar is visible, now that the user
  //has logged in
  ShowTaskBar;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  //Only allow the program to close, if the correct
  //password has been entered ...
  CanClose := CloseIsOK;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  //This button/code is merely here to make development
  //easier, i.e so I'm able to close the program, without entering password
  //Just remove this button when the program is ready
  CloseIsOK := True;
  Close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  //Lets do the actual password validation:
  if (MEdPassw.Text = Password) then
    begin
      //Password is correct, program closes ...
      CloseIsOK := True;
      Close;
    end
  else
    begin
      //Wrong password entered
      //Add 1 to Counter
      Inc(Counter);
      MEdPassw.Text := '';
      MEdPassw.SetFocus;
      if counter = 3 then
        begin
          //Wrong Password has been entered 3 times
          //we should display an error.
          MessageDlg('Invalid Login!',MtError,[MbOK],0);
          //Set counter to zero ...
          Counter := 0;
        end;
    end;
end;

end.
