Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

How do I include a password form into my program?

Posted on 2000-03-21
9
Medium Priority
?
221 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Accepted Solution

by:
westy100697 earned 280 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

647 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