给你一个以前的很早以前写的登录代码吧
function LoginUser(UserName, PassWord: String):Boolean;
//用户登录: 用户名;用户密码
var
i: Integer;
begin
Result:=False;
try
Query.Close;
Query.SQl.Clear;
Query.SQL.Add('Select * from [用户管理表] where [用户姓名]='''
+Encode(UserName)+'''');
if PassWord='' then
Query.SQL.Add(' and ([用户密码]='''' or [用户密码] is NULL)')
else
Query.SQL.Add(' and [用户密码]='''+Encode(PassWord)+'''');
Query.Open;
if Query.isEmpty then
begin
LogTimes:=LogTimes+1;
if LogTimes>2 then
begin
MessageBox(Application.Handle,PChar('用户名或密码错误,无法登录系统!'
+' '+#13#13'错误次数已达3次,即将退出系统!'),'提示',MB_OK+
MB_ICONINFORMATION);
Application.Terminate;
end
else
MessageBox(Application.Handle,'用户名或密码错误,无法登录系统! ',
'提示',MB_OK+MB_ICONINFORMATION);
Exit;
end
Result:=True;
Query.Close;
except
on E:Exception do
ErrMsg(E);
end;
end;