unit loginU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, inifiles;
type
TFload = class(TForm)
Edtname: TEdit;
edtpassword: TEdit;
Label1: TLabel;
Label2: TLabel;
BitBtn2: TBitBtn;
Label3: TLabel;
Edtsuper: TEdit;
BitBtn1: TBitBtn;
procedure BitBtn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure edtpasswordKeyPress(Sender: TObject; var Key: Char);
procedure EdtnameKeyPress(Sender: TObject; var Key: Char);
procedure BitBtn1Click(Sender: TObject);
private
icount: integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Fload: TFload;
superpasswordflag: boolean;
implementation
uses mainkehgl, usermsg;
{$R *.DFM}
procedure TFload.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := CaFree;
end;
procedure TFload.FormCreate(Sender: TObject);
begin
superpasswordflag := false;
end;
procedure TFload.FormShow(Sender: TObject);
begin
Edtname.SetFocus;
if superpasswordflag = true then
begin
Label3.visible := true;
Edtsuper.visible := true;
end;
end;
procedure TFload.edtpasswordKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
BitBtn1.setfocus;
end;
procedure TFload.EdtnameKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
edtpassword.setfocus;
end;
procedure TFload.BitBtn1Click(Sender: TObject);
var scurrtdir: string;
logini: tinifile;
strtemp: string;
begin
scurrtdir := getcurrentdir;
logini := tinifile.create(scurrtdir + '/' + 'manager.ini');
try
globmanager := trim(edtname.Text);
strtemp := lowercase(logini.readstring(trim(edtname.text), 'password', 'error'));
if superpasswordflag = false then
begin
if (lowercase(trim(edtpassword.text)) = strtemp) or ((lowercase(trim(edtname.text)) = 'admin') and (lowercase(trim(edtpassword.text)) = 'admin')) //系统管理员用户
then self.ModalResult := mrok
else if (trim(edtname.text) = '') or (trim(edtpassword.text) = '')
then
begin
showmessage('输入不能为空,请重新输入!');
inc(icount);
if icount = 3 then
begin
showmessage('非法登录!请退出!');
close;
end;
edtname.text := '';
exit;
end
else if (lowercase(trim(edtpassword.text)) <> strtemp) then
if ((lowercase(trim(edtname.text)) <> 'admin') and (lowercase(trim(edtpassword.text)) <> 'admin'))
then
begin
inc(icount);
if icount = 3 then
begin
showmessage('非法登录!请退出!');
close;
end;
showmessage('用户名和密码输入错误!!');
edtpassword.text := '';
exit;
end;
end
else
begin
if ((lowercase(trim(edtpassword.text)) = strtemp) or ((lowercase(trim(edtname.text)) = 'admin') and (lowercase(trim(edtpassword.text)) = 'admin'))) and (lowercase(trim(Edtsuper.text)) = 'adminyt')
then
begin
Edtsuper.visible := false;
Label3.visible := false;
self.ModalResult := mrok;
end
else
begin
inc(icount);
if icount = 3 then
begin
showmessage('非法登录!请退出!');
close;
end;
showmessage('输入错误,请重新输入!');
exit;
end;
end;
finally
logini.free;
end;
end;
procedure TFload.BitBtn2Click(Sender: TObject);
begin
close;
end;
end.
在主程序中判断返回值ModalResult。