程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 用Delphi建立應用軟件注冊安全機制(4)

用Delphi建立應用軟件注冊安全機制(4)

編輯:Delphi

13.創建注冊過程。雙擊注冊按 鈕(LoginBitBtn),在begin和end之間輸入其OnClick事件處理程序代碼:

ModalResult:=mrNone;
try
Session.AddPassword(UserPassWord);
LogDataModule.UsersTable.Open;
//注冊信息處理
ifnotLogDataModule.UsersTable.FindKey
([LoginNameEdit.Text,PassWordEdit.Text]) then
begin
//處理注冊次數
dec(CountDown);
ifCountDown=0thenModalResult:=mrCancel else
begin
MessageBeep($FFFF);
Application.MessageBox(請您重試一次!,無效注冊信息,mb_iconstop+mb_OK);
//重設輸入焦點
LoginNameEdit.SetFocus;
end;
exit;
end;
//檢查注冊允許值
ifnotLogDataModule.UsersTable.FIEldByName(Enabled).AsBoolean then
begin
MessageBeep($FFFF);
Application.MessageBox(抱歉,您不能進入系統!,使用權限終止,mb_iconexclamation+mb_OK);
ModalResult:=mrCancel;
exit;
end;
//獲取注冊用戶信息
withLogDataModuledo
begin
LoginUser.UserName:=UsersTable.
FIEldByName(Name).AsString;
LoginUser.UserFullName:=UsersTable.
FIEldByName(Fullname).AsString;
LoginUser.UserGroup:=UsersTable.
FIEldByName(Group).AsInteger;
End;
ModalResult:=mrOK;
//關閉表,清除密碼
finally
LogDataModule.UsersTable.Close;
Session.RemovePassword(UserPassWord);
end;

14.在Main.pas單元的uses中 加入Addition,在Login.pas單元的implementation段增加uses 語句:

usesMD,Addition;

15.打開過程文件Register.dpr, 在uses語句中加入Controls,將Application.run;改為下列語句,只有注冊成功時才啟動系統,同時釋放注冊窗體,以確保安 全和減少內存占用。

ifLoginDialogForm.ShowModal=mrOKthen
begin
LoginDialogForm.Free;
Application.Run;
end;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved