Link to home
Start Free TrialLog in
Avatar of chris_emptage
chris_emptage

asked on

How do I include a password form into my program?

How can I include a password log in form at the start of my program? I need to be able to have several users and be able to change the passwords. Is it possible to have stars coming up on screen instead of the password as you do when you log on to Windows NT?
Thankyou very much.
Chris
Avatar of chris_emptage
chris_emptage

ASKER

Thankyou very much to anyone who answers this problem of mine.
for the stars, use the passwordchar property of you field.
Set it to * or ¤ or whatever you like.
You need 2 forms: Form1 and Form2. Form2 has 2 editboxes and 2 buttons.


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
begin
  if Form2.ShowModal = mrOk then
    ShowMessage('Welcome')
  else begin
    ShowMessage('Login failed');
    Application.Terminate;
  end;
end;

end.



unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm2 = class(TForm)
    Username: TEdit;
    Password: TEdit;
    Login: TButton;
    Abort: TButton;
    procedure LoginClick(Sender: TObject);
    procedure AbortClick(Sender: TObject);
    procedure PasswordKeyPress(Sender: TObject; var Key: Char);
    procedure UsernameKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.LoginClick(Sender: TObject);
const VALIDPASSWORD = 'pass';
begin
  if Password.Text = VALIDPASSWORD then
    ModalResult := mrOk
  else
    ModalResult := mrAbort;
end;

procedure TForm2.AbortClick(Sender: TObject);
begin
  ModalResult := mrAbort
end;

procedure TForm2.PasswordKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    LoginClick(Self);
end;

procedure TForm2.UsernameKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
    Password.SetFocus;
end;

end.
ASKER CERTIFIED SOLUTION
Avatar of westy100697
westy100697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in project source:

PasswordDlg := TPasswordDlg.Create(Application);
  PasswordDlg.ShowModal; //set tag to 1 if password is Okee.
  PasswordDlg.Update;
  if passwordDlg.tag = 1 then
     begin
     //password controle Okee.
     Application.CreateForm(TForm1, Form1);
     Application.Run;
     end
  else
    begin
    //password not Okee.
    end;
Adjusted points from 50 to 70
Thankyou very much for your answer! It was very great of you to show me this. Unfortuneately though i am not exactly god's gift to Delphi and had trouble understanding what you had written. I was not sure what went where and so I was unable to get it working. But cheers anyway,
Chris
chris_emptage,
              If you want a more thorough and basic explanantion I can e-mail you something to that effect, only if you want me to??

WESTY :)  
 
Westy
If you could e-mail me an explanation that would great. My address is chris_emptage@hotmail.com If there is anything I can do for you just let me know. Cheers very very much, I've been having so many problems with this program.
Chris