As part of my A-Level computing coursework i have to simulate an end user and design a programe for them.
I have the code to allow for a listbox were you select from a list of usernames you want but for added security i want to ammend it so you have to type in both the username and password (in text boxes) not just select one of the optional usernames (in the listbox). the code i have that works for the list box is as follows. Can anyone tell me how i can change my code so that you must type in the username?
for easy reading the username box is called TxtUsername and the password box is TxtPasword
thanks in advanced
my code is as follows:
unit RSPCA;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg;
type
TFrmRSPCALogin = class(TForm)
BtnLogin: TButton;
BtnExit: TButton;
TxtPassword: TEdit;
TxtUsername: TEdit;
Image1: TImage;
LblUsername: TLabel;
Label1: TLabel;
procedure BtnExitClick(Sender: TObject);
procedure BtnLoginClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmRSPCALogin: TFrmRSPCALogin;
implementation
type
Tuser = record
s_Username : string;
s_Password : string;
i_type : integer;
end;
const
USERS = 'Users.txt';
SETTINGS = 'Settings.txt';
var
a_user : array [0..15] of TUser;
i_logins : integer;
i_maxlogins : integer;
{$R *.dfm}
procedure TFrmRSPCALogin.BtnExitClick(Sender: TObject);
begin
Application.Terminate;
end;
procedure TFrmRSPCALogin.BtnLoginClick(Sender: TObject);
var
fp_settings : textFile;
begin
inc(i_logins);
if i_logins > i_maxlogins then
begin
messagedlg('To many Login Attempts, Program Is Now Locked!', mtError, [mbOk], 0);
AssignFile(fp_settings, SETTINGS);
Rewrite(fp_settings);
WriteLn(fp_settings, '1');
WriteLn(fp_settings, InttoStr(i_maxlogins));
CloseFile(fp_settings);
Application.terminate;
end else
begin
if Uppercase(trim(TxtPassword.Text)) =
Uppercase(trim(a_User[TxtUsername.ItemIndex].s_password)) then
begin
s_username := a_user[LstUsers.Itemindex.s_Username;
FrmPassword.Hide;
Application.CreateForm(TFrmMain, FrmMain);
FrmMain.Show;
end else
begin
MessageDlg('Wrong Password!', mtError, [mbOk], 0);
TxtPassword.Clear;
TxtPassword.setFocus;
end;
end;
end;
procedure TFrmRSPCALogin.FormCreate(Sender: TObject);
var
fp_users : Textfile;
fp_settings : Textfile;
i_users : integer;
s_temp : string;
begin
if FileExists(SETTINGS) then
begin
AssignFile(fp_settings, SETTINGS);
reset(fp_Settings);
ReadLn(fp_settings, s_temp);
if s_temp <> '0' then
begin
MessageDlg('Program is Locked!', mtError, [mbOk], 0);
Application.terminate;
end else
begin
ReadLn(fp_settings, s_temp);
i_maxlogins := StrToInt(s_temp);
end;
CloseFile(fp_settings);
end else
begin
MessageDlg('Missing Settings Files!', mterror, [mbOk], 0);
Application.terminate;
end;
if FileExists (USERS) then
begin
AssignFile(fp_users, USERS);
Reset(fp_USERRS);
i_users := 0;
while not EOF(fp_users) do
begin
ReadLn(fp_Uers, a_user[i_users].s_username);
LstUsers.items.Add(a_user[i_users].s_username);
ReadLn(fp_Users, a_user[i_users].s_password);
ReadLn(fp_users, s_temp);
a_User[i_users].i_type := StrToInt(s_temp);
inc(i_users);
end;
closeFile(fp_users);
end;i_logins :=0;
end else
begin;
MessageDlg('Password File does not exist!', mtError, [mbOk], 0);
Application.terminate;
end;
end;
end.