菜鸟的两段DELPHI窗口登陆验证代码
varForm1: TForm1;
count:integer;
implementation
uses unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
count:=1;
if Form1.Edit1.Text='' then
showmessage('请输入用户名!')
else if Form1.Edit2.Text='' then
showmessage('请输入密码!')
else
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select Password from logon where user='''+ trim
(EDit1.Text)+'''';
ADOQuery1.Open;
if ADOQuery1.FieldByName('Password').AsString=EDit2.Text then
begin
Form1.Hide;
Form2.show
end
else
begin
showmessage('密码错误,请从新输入!');
inc(count);
if (count=3)then
exit
end
end
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
end unit psd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables;
type
TForm1 = class(TForm)
Table1: TTable;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
count:integer; //设置全程整型变量作为计数器
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
results:variant;
begin
if Edit1.Text=''then
showmessage('用户名不能为空!');
if Edit2.Text='' then
showmessage('请输入密码!');
count:=count+1;//计数加1
results:=table1.Lookup('users',Edit1.Text,'password');
//检索数据库中对应的用户名的密码项
if results=Edit2.Text then
showmessage('密码确认,即将进入学生信息管理系统。')
//如果对应相同则进入,此处只是演示,所以只是简单说明密码确认
else
begin
showmessage('错误的用户名或密码!');//密码不确认
if(count=3) then
close;//三次错误,强制退出
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
table1.Active:=true;//窗体初始化,连接数据库
count:=0
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
if(Edit2.Text=#13)then//当在edit2中输入密码后,按回车键,执行密码查询
Button1.Click
else
end;
end. 第一段代码 要求 数据库名取为logon
权限设定是登陆三次,密码错误报错!
页:
[1]