Solved

How do I include a password form into my program?

Posted on 2000-03-21
9
215 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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