这个就100分,分太多了吧
三次密码验证的话,可以用一个自增的变量来保存非法登陆的次数,到三次就application.Terminate出来
三次密码验证的话,可以用一个自增的变量来保存非法登陆的次数,到三次就application.Terminate出来
解决方案 »
- DBGridEh绑定字段的情况下,如何触发OnDrawDataCell事件?
- 如何改变程序的图标?
- 有没有完全免费的条码打印控件
- 怎樣使adodataset獲得的數據集﹐可以進行修改?請指教﹗
- DBgridEH如何把格式设成财务记账凭证的表格式,就是一个字段格内分成很多竖线
- 这个问题有点怪
- 在WINDOW2000下怎样驱动猫?
- 请教有没有判断日期格式是否正确的函数?
- 各位Delphi前辈,请教如何实现对IE编程,使其能实现直接打开并运行联接的本机的.exe文件,而不是显示下载的对话框?
- 如何设置DBGRID 的行的颜色 送50 分给大家
- 怎么样访问数据库中的数据?
- 高兴,第二次来给分,高手再进来拿分!100分先给你们
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Edit_pass: TEdit;
Button_ok: TButton;
Button_cancel: TButton;
Label1: TLabel;
Label2: TLabel;
Edit_username: TEdit;
procedure Button_okClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
m_Times: integer;
implementation{$R *.DFM}procedure TForm1.Button_okClick(Sender: TObject);
begin
if (Edit_username.Text = 'X度空间') and (Edit_pass.Text = 'X度空间') then
begin
showmessage('验证通过了,进入你的主程序');
end
else
begin
showmessage('验证失败了,叫用户重新输入吧,'+#13+'还有'+inttostr(2-m_times)+'次机会');
inc(m_times);
if m_times = 3 then //3次都错了,自动退出
application.Terminate;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
m_times := 0;
end;end.
(这个是pas文件)
object Form1: TForm1
Left = 192
Top = 107
Width = 418
Height = 153
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 88
Top = 48
Width = 57
Height = 13
Caption = 'password:'
end
object Label2: TLabel
Left = 88
Top = 16
Width = 58
Height = 13
Caption = 'username:'
end
object Edit_pass: TEdit
Left = 168
Top = 44
Width = 177
Height = 21
TabOrder = 0
Text = 'Edit_pass'
end
object Button_ok: TButton
Left = 48
Top = 80
Width = 113
Height = 33
Caption = 'Button_ok'
TabOrder = 1
OnClick = Button_okClick
end
object Button_cancel: TButton
Left = 216
Top = 80
Width = 113
Height = 33
Caption = 'Button_cancel'
TabOrder = 2
end
object Edit_username: TEdit
Left = 168
Top = 12
Width = 177
Height = 21
TabOrder = 3
Text = 'Edit_username'
end
end
procedure TLoginForm.BitBtn1Click(Sender: TObject);
begin
try
inc(passtime);
if (usernameEdit.Text='')or(passwordEdit.Text='') then
begin
showmessage('用户名或口令为空');
exit;
end;
with hotelDataModule do
begin
loginquery.Close;
loginquery.SQL.Clear;
loginquery.SQL.Add('select * from manager where manager='+''''+usernameEdit.Text+''''+
' and password='+''''+passwordEdit.Text+'''');
loginquery.Open;
if loginquery.RecordCount=1 then
begin
right:=loginquery.fieldbyname('rright').AsString;
Mainform.Enabled:=true;
usernameEdit.Clear;
passwordEdit.Clear;
close;
end
else
begin
if passtime<3 then
begin
showmessage('用户名和口令有误');
usernameEdit.SetFocus;
passwordEdit.Clear;
end
else//密码输入错误超过三次
begin
MessageBox(Handle,'连续输入错误密码超过3次,程序退出!','信息',MB_OK);
BitBtn2Click(Sender);
end;
end;
end;
except
showmessage('异常产生');
end;
end;
//初始化
procedure TLoginForm.FormCreate(Sender: TObject);
begin
passtime:=0;
end;
program Mclient;uses
Forms,
uimage in 'uimage.pas' {fimage},
addimage in 'addimage.pas' {faddimage},
main in 'main.pas' {Fmain},
logno in 'logno.pas' {Flogno},
look in 'look.pas' {flook},
admdel in 'admdel.pas' {fadmdel},
admedit in 'admedit.pas' {fadmedit},
admini in 'admini.pas' {fadmin},
mdata in 'mdata.pas' {fmdata: TDataModule},
GIFImage in '..\Bg&kl cs\gifimage.pas',
pr in 'pr.pas' {fprint};{$R *.RES}begin
Application.Initialize;
try
begin
Application.Title := '软件';
Application.CreateForm(Tfmdata, fmdata);
flogno:= Tflogno.Create(Application);
flogno.ShowModal;
if logno.logno_ok then
begin
Application.CreateForm(TFmain, Fmain);
Application.CreateForm(Tfaddimage, faddimage);
Application.CreateForm(Tflook, flook);
Application.CreateForm(Tfadmdel, fadmdel);
Application.CreateForm(Tfadmedit, fadmedit);
Application.CreateForm(Tfadmin, fadmin);
Application.CreateForm(Tfimage, fimage);
end;
Application.Run;
end;
except
begin application.Terminate;
end;
end;end.
unit logno;登陆单元
interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
DBCtrls, StdCtrls, Buttons, Mask,db, ExtCtrls, ToolWin, ComCtrls;type
TFlogno = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
editm: TMaskEdit;
Bevel1: TBevel;
Image1: TImage;
StaticText1: TStaticText;
look: TDBLookupComboBox;
CoolBar1: TCoolBar;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure Edit1Exit(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure lookExit(Sender: TObject);
procedure editmKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;var
Flogno: TFlogno;
lon:integer;
logno_ok:bool;
implementationuses mdata, main;{$R *.DFM}procedure TFlogno.FormCreate(Sender: TObject);
begin
lon:=0;
main.admme:=9999;
logno_ok:=false;
end;procedure TFlogno.Edit1Exit(Sender: TObject);
var serch:bool;
begin
serch:=fmdata.dadm.Locate('admindex',vararrayof([edit1.text]),
[]);
if serch then
look.KeyValue:=fmdata.dadm.fieldbyname('admname').asstring
else
look.KeyValue:='';end;procedure TFlogno.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
{
if (key=#8) then
else
if (key<>#13) then
begin
if (key<#48) or (key>#57) then
key:=#0;
if (length(edit1.Text)=4) then
key:=#0;
end;}
if not (key in['0'..'9',#13,#8]) then
key:=#0;
end;
procedure TFlogno.FormKeyPress(Sender: TObject; var Key: Char);
beginif key=#13 then
Perform(WM_NEXTDLGCTL, 0, 0);end;procedure TFlogno.SpeedButton1Click(Sender: TObject);
var str1,str2,str3,str4:string;
begin
str1:=editm.text;
str2:=trim(fmdata.dadm.fieldbyname('admma').asstring);
str3:=edit1.text;
str4:=trim(fmdata.dadm.fieldbyname('admindex').asstring);
if fmdata.dadm.FieldByName('online').asboolean then
begin
showmessage('该用户已经登陆到服务器上了,请你不要再用该用户名登陆!!!');
end
else
begin
if (str1=str2) and (str3=str4) then
begin
logno_ok:=true;
close;
fmdata.dadm.Edit;
fmdata.dadm.FieldByName('LONDTS').AsDateTime:=date+time;
//fmdata.dadm.fieldbyname('lonts').asdatetime:=time;
fmdata.dadm.FieldByName('online').AsBoolean:=logno_ok;
fmdata.dadm.FieldByName('londte').clear;
//fmdata.dadm.fieldbyname('lonte').clear;
fmdata.dadm.ApplyUpdates(-1);
main.admname:=fmdata.dadm.fieldbyname('admname').asstring;
main.admindex:=str4;
main.admme:=fmdata.dadm.fieldbyname('admme').asinteger;
end
else
begin
lon:=lon+1;
editm.Clear;
end;
if lon>2 then
begin
application.Terminate;
end;
end;
end;procedure TFlogno.SpeedButton2Click(Sender: TObject);
beginapplication.Terminate;
end;procedure TFlogno.lookExit(Sender: TObject);
begin
edit1.Text:=fmdata.dadm.fieldbyname('admindex').asstring;
end;procedure TFlogno.editmKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
speedbutton1.Click();
end;end.
你在
showmessage('验证通过了,进入你的主程序');
这里怎么处理登录窗口和主程序的关系,也就是
登录窗口的释放和主程序的加载!
procedure TForm1.Button1Click(Sender: TObject);
begin
application.CreateForm(TForm2,Form2);
Form2.Show;
Form1.Free;
end;
如果你要在Form2里面结束程序,加入一个Button,在OnClick里面写
procedure TForm2.Button1Click(Sender: TObject);
begin
application.Terminate;
end;
就行了
先跳出来登陆窗口,密码错误就关掉。密码通过进入主Form.
我就是用这种方法!
不以星三角论英雄,以技术论英雄!
CREATE procedure user_check
@user_name varchar (20),
@userpwd varchar (20),
@result varchar(5) output
as
if exists (select * from [users] where [user_name]=@user_name and userpwd=@userpwd)
set @result ='ok'
else set @result ='false'
GO/////////////////////////////
var times:integer;
procedure TloginForm.BitBtn1Click(Sender: TObject);
var
a:string;begin
inc(times);
//使用user_check存储过程来验证密码
dm.user_check.Parameters.ParamByName('@user_name').Value:=edit1.Text;
dm.user_check.Parameters.ParamByName('@userpwd').Value:=edit2.Text;
dm.user_check.Prepared:=true;
dm.user_check.ExecProc;
a:=dm.user_check.Parameters.ParamByName('@result').Value;
if a='ok' then
begin
loginform.Close;
mainform.enabled:=true;
mainform.Show ;
mainform.Timer1.Enabled :=false; mainform.StatusBar1.Panels[0].Text:='当前登录的用户为'+loginform.Edit1.Text+''+'登录时间是'+datetimetostr(now);
end
else
begin
if times<3 then
begin
loginform.show;
mainform.Enabled :=false;
mainform.Timer1.Enabled :=false;
// mainform.Label2.Visible:=false;
showmessage('您输入的密码或用户名有误!');
edit2.SetFocus ;
end
else
begin
if MessageBox(handle,'连续输入三次错误,系统将自动退出!','错误',MB_OK)=IDOK then
Application.Terminate;
end;
end;
end;