Solved

How do I include a password form into my program?

Posted on 2000-03-21
9
216 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:chris_emptage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 

Author Comment

by:chris_emptage
ID: 2641383
Thankyou very much to anyone who answers this problem of mine.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2641403
for the stars, use the passwordchar property of you field.
Set it to * or ¤ or whatever you like.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2641487
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
westy100697 earned 70 total points
ID: 2642001
chris_emptage,
              There are many ways to include a password log form into the start of your program. I personally use
a database table to store passwords, usernames and levels of access. I also do not allow access to my program unless the user logs in. This is done by making sure you show the logon from through the source of your project as the last form created.

I use this in my project source....

begin
  Application.CreateForm(TMainForm, MainForm);
  Application.CreateForm(TSplashScreen,  SplashScreen);
  Application.CreateForm(TDataModule1, DataModule1);
  SplashScreen.Showmodal ;
  LogonForm := TLogonForm.Create(Application) ;
  LogonForm.Showmodal ;

  Application.Run;

end.


For the logon form I just have  a
dbgrid listing the usernames and levels of users, 1 edit box for entering the password and 2 buttons. 1 button is the login button and 1 is a cancel button.

This is the code from my logon form using a database table.....

unit logon;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids, DBGrids,fmMain, Buttons, DosMove;

type
  TLogonForm = class(TForm)
    DBGrid1: TDBGrid;
    Label1: TLabel;
    Password: TEdit;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDeactivate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure PasswordKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  LogonForm: TLogonForm;

implementation
uses
 Splash, dmLogon
{$R *.DFM}
{$OPTIMIZATION OFF}

procedure TLogonForm.FormCreate(Sender: TObject);
begin
  Datamodule2.UserTable.Open ;
  Datamodule3.LogTable.Open ;
end;

procedure TLogonForm.FormActivate(Sender: TObject);
begin
  Datamodule2.UserTable.Active := true ;
  Datamodule3.LogTable.Active := true ;
end;

procedure TLogonForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Datamodule2.UserTable.Close ;
  Datamodule3.LogTable.Close ;
  Release ;
end;

procedure TLogonForm.FormDeactivate(Sender: TObject);
begin
  Datamodule2.UserTable.Active := false ;
  Datamodule3.LogTable.Active := false ;
end;

procedure TLogonForm.BitBtn1Click(Sender: TObject);
var
  TempPass : String ;
begin
  with Datamodule2.UserTable do
  begin
    TempPass := FieldByName('PASSWORD').AsString ;
    if AnsiUpperCase(Password.Text) = FieldByName('PASSWORD').AsString then
    begin
      fmMain.UserName      := FieldByName('NAME').AsString;
      fmMain.UserLevel     := FieldByName('LEVEL').AsInteger;
      fmMain.UserPassword  := FieldByName('PASSWORD').AsString;
      fmMain.UserID        := FieldByName('ID').AsString;
      Password.Text := '';
      LogonForm.close;
    end
    else
    begin
      MessageDlg('Incorrect Password. Please enter password again.',mtError, [mbOK], 0);
      Password.Text := '';
    end;
  end;
  if AnsiUpperCase(Password.Text) = TempPass then
  begin
    Datamodule3.Helpa32LogTable.Append ;
    Datamodule3.LogTable.fieldbyname('THEUSER').AsString := FmMain.UserName;
    Datamodule3.LogTable.fieldbyname('THEDATE').AsString := FormatDateTime('dd/mm/yyyy',Now);
    Datamodule3.LogTable.fieldbyname('THETIME').AsString := FormatDateTime('hh:mm:ss am/pm',Time);
    Datamodule3.Helpa32LogTable.fieldbyname('EVENTS').AsString := 'Logged On to Helpa32';
    Datamodule3.Helpa32LogTable.Post ;
    Datamodule3.Helpa32LogTable.Close ;
  end;
end;

procedure TLogonForm.BitBtn2Click(Sender: TObject);
begin
  Close ;
end;

procedure TLogonForm.DBGrid1CellClick(Column: TColumn);
begin
  Password.SetFocus ;
end;

procedure TLogonForm.PasswordKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If Key = VK_RETURN then
   BitBtn1Click(Sender);
end;

end.


I hope you may be able to use this. There is already one suggestion here but I thought you may like to see another method.


WESTY :)
0
 
LVL 2

Expert Comment

by:florisb
ID: 2643858
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;
0
 

Author Comment

by:chris_emptage
ID: 2645771
Adjusted points from 50 to 70
0
 

Author Comment

by:chris_emptage
ID: 2645774
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
0
 

Expert Comment

by:westy100697
ID: 2646812
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 :)  
 
0
 

Author Comment

by:chris_emptage
ID: 2650746
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question