|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
在这个加密程序中多了一个密码验证的简单算法,可是当第一次密码错误后,第二次不输入密码,在点确定按钮,显示成功登陆了,这是哪里出了问题?求解: 附上代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
lbl1: TLabel;
edt1: TEdit;
btn1: TButton;
chk1: TCheckBox;
procedure edt1Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure chk1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
passwd:string ='pcwind';
n:Integer = 3;
showpasswd:Boolean = False;
{$R *.dfm}
procedure TForm1.edt1Click(Sender: TObject);
begin
edt1.Clear;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
passwd2:string;
passwd3:string;
begin
passwd2:=passwd;
Delete(passwd2,1,3);
passwd3:= edt1.Text;
Delete(passwd3,1,3);
passwd:= passwd2;
if (passwd3 = passwd ) then
MessageBox(Handle,'恭喜,欢迎您!','恭喜', MB_OK)
else
begin
n:= n-1;
if (n<1)then
begin
lbl1.Caption:='你的输入次数已达到3次!';
MessageBox(Handle,'密码错误,程序自动关闭!','警告', MB_OK or MB_ICONSTOP);
Close;
end
else
begin
lbl1.Caption:='请重新输入,您还有'+ IntToStr(n) +'次机会!';
edt1.Clear;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(edt1.Handle,GWL_STYLE,GetWindowLong(edt1.handle,GWL_STYLE) or ES_CENTER);
edt1.invalidate;
end;
procedure TForm1.chk1Click(Sender: TObject);
begin
showpasswd:= not showpasswd;
if (showpasswd = true )then
edt1.PasswordChar:=#0
else
edt1.PasswordChar:='*'
end;
end. |
|