如何进行用户验证界面设计?(100分)

  • 主题发起人 主题发起人 sailor9
  • 开始时间 开始时间
S

sailor9

Unregistered / Unconfirmed
GUEST, unregistred user!
[:)]我不知如何进行用户验证界面设计?那位帮帮忙,谢谢!
 
在mainform中的onshow事件调用那个验证窗口进行验证嘛.
假如用户是存放在一个表里,那么你在logon窗口进行验证就行了
搞一个全局变量,当验证通过时就把它置为相应标志,在mainform中判断
如果通过那么就继续.否则application.terminate
 
话虽如此,以前我也如此做过,但我总实现不了?
 
在项目文件中:
Application.CreateForm(TLoginForm, LoginForm);
if LoginForm.showmodal=idok then
begin
Application.Initialize;
Application.Run;
end;

大体上是这样了,你自已在loginform中加入代码返回值就行了。
 
用数据库,把用户名和密码放在一个数据库里面,调用就行了!数据库,用sql查询就行了!
 
procedure Tmainfrm.Formshow(Sender: TObject);
var
logon_frm:Tlog_frm;
begin


//显示登录窗口,验证用户

logon_frm:=Tlog_frm.create(Application);
logon_frm.showmodal;

if conn_flag=0 then
Application.terminate;
end;
其中conn_flag是全局变量;
 
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。
 
后退
顶部