惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threat Research - Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
P
Proofpoint News Feed
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
A
About on SuperTechFans
T
Tenable Blog
M
MIT News - Artificial intelligence
IT之家
IT之家
I
Intezer
D
DataBreaches.Net
爱范儿
爱范儿
T
Threatpost
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
K
Kaspersky official blog
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Darknet – Hacking Tools, Hacker News & Cyber Security
H
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
AWS News Blog
AWS News Blog
博客园 - 聂微东
C
Check Point Blog
S
Securelist
有赞技术团队
有赞技术团队
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
D
Docker
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
L
Lohrmann on Cybersecurity
G
Google Developers Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog

博客园 - 万一

关于内存数据与 JSON 高亮 TRichEdit 当前行 使用 IntraWeb (45) - 活用 IntraWeb 使用 IntraWeb (44) - 测试读取 SqLite (三) 使用 IntraWeb (43) - 测试读取 SqLite (二) 使用 IntraWeb (42) - 测试读取 SqLite (一) 使用 IntraWeb (41) - 数据控件速查 使用 IntraWeb (40) - 自定义 Session 数据 使用 IntraWeb (39) - THttpRequest、THttpReply 使用 IntraWeb (38) - TIWAppForm、TIWForm、TIWBaseHTMLForm、TIWBaseForm 使用 IntraWeb (37) - TIWApplication 使用 IntraWeb (36) - TIWServerControllerBase 使用 IntraWeb (35) - TIWJQueryWidget 使用 IntraWeb (34) - TIWAJAXNotifier 使用 IntraWeb (33) - Cookie 使用 IntraWeb (32) - Url 映射与 THandlers 使用 IntraWeb (31) - IntraWeb 的 Xml 操作使用的是 NativeXml 使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache 使用 IntraWeb (28) - 基本控件之 TIWTemplateProcessorHTML、TIWLayoutMgrHTML、TIWLayoutMgrForm
使用 IntraWeb (29) - 基本控件之 TIWAutherList、TIWAutherINI、TIWAutherEvent
万一 · 2014-06-20 · via 博客园 - 万一

TIWAutherList  //通过一组户名与密码验证登陆
TIWAutherINI   //通过记录户名与密码信息的 #Auth.ini 文件验证登陆
TIWAutherEvent //通过其 OnCheck 事件验证登陆

{作为站点级的验证, 验证控件应该是放在 ServerController 的窗体上, 并与其 Auther 属性关联.}

TIWAutherList 所在单元及继承链:
IWAutherList.TIWAutherList < TIWAutherBase < TComponent < TPersistent < TObject

主要成员:


property List: TStrings	//户名与密码表; 每行按 User=Pass 的格式输入
property AutherPolicy: TAutherPolicy //该属性有两个选项 apRestrictAll(默认)、apRestrictNone(选这个表示不执行验证)

property OnAuthenticate: TOnAuthenticate //验证成功后执行的事件 

测试 TIWAutherList:


{在 ServerController 的窗体上放置 IWAutherList1, 然后双击该窗体(激活其 OnCreate 事件)}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
  Self.Auther := IWAutherList1;
  IWAutherList1.List.Add('aaa=111');
  IWAutherList1.List.Add('bbb=222');
  IWAutherList1.List.Values['ccc'] := '333';
end;

{这就好了, 如果在设计时完成上面工作会更方便}


TIWAutherINI 所在单元及继承链:
IWAutherINI.TIWAutherINI < TIWAutherBase < TComponent < TPersistent < TObject

主要成员:


property AutherPolicy: TAutherPolicy //

property OnAuthenticate: TOnAuthenticate //

{它需要的 ini 文件须命名为 #Auth.ini(它会保证不被用户读取, 应该使用 UTF8 格式保存), 并且和程序文件放在同一目录(而非 wwwroot 下)}

{其格式规范:--------------------
[户名1]
Password=密码1
[户名2]
Password=密码2
...
------------------------------}

{建好文件, 放对地方, 再关联上 Auther 属性就可以了}

TIWAutherEvent 所在单元及继承链:
IWAutherEvent.TIWAutherEvent < TIWAutherBase < TComponent < TPersistent < TObject

主要成员:


property AutherPolicy: TAutherPolicy //

property OnCheck: TOnCheck		 //就是在该事件中验证; 假如要从数据库验证就应该用这种方法
property OnAuthenticate: TOnAuthenticate //

{更多时候可能需要把验证函数写在 UserSessionUnit 单元(譬如通过数据库验证时), 这时应该保证 IWServerController.AuthBeforeNewSession = False(这也是默认值)}

测试 TIWAutherEvent:


{IWAutherEvent1 的 OnCheck 事件}
function TIWServerController.IWAutherEvent1Check(const aUser, aPass: string): Boolean;
begin
  Result := aPass = aUser + '123'; //假如密码是: 用户名+123
end;

{需要保证关联到 Auther 属性}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
  Auther := IWAutherEvent1;
end;

还是上面的例子, 现在改成通过 TIWUserSession 的一个方法来验证:


{UserSessionUnit.pas}

unit UserSessionUnit;

interface

uses
  IWUserSessionBase, SysUtils, Classes;

type
  TIWUserSession = class(TIWUserSessionBase)
  private
  public
    function MyCheck(const AUser, APass: string): Boolean;
  end;

implementation

{$R *.dfm}

{ TIWUserSession }

function TIWUserSession.MyCheck(const AUser, APass: string): Boolean;
begin
  Result := APass.ToLower = AUser.ToLower + '123';
end;

end.


{-------------------------------------------------}


{ServerController.pas, 有注释的是自己添加的代码}

unit ServerController;

interface

uses
  SysUtils, Classes, IWServerControllerBase, IWBaseForm, HTTPApp,
  UserSessionUnit, IWApplication, IWAppForm, IW.Browser.Browser, IWAutherEvent, IWAutherINI, IWAutherBase, IWAutherList;

type
  TIWServerController = class(TIWServerControllerBase)
    IWAutherEvent1: TIWAutherEvent;
    procedure IWServerControllerBaseNewSession(ASession: TIWApplication);
    procedure IWServerControllerBaseCreate(Sender: TObject);
    function IWAutherEvent1Check(const aUser, aPass: string): Boolean;
  private
  public
  end;

function UserSession: TIWUserSession;
function IWServerController: TIWServerController;

implementation

{$R *.dfm}

uses
  IWInit, IWGlobal;

function IWServerController: TIWServerController;
begin
  Result := TIWServerController(GServerController);
end;

function UserSession: TIWUserSession;
begin
  Result := TIWUserSession(WebApplication.Data);
end;

{IWAutherEvent1 的 OnCheck 事件, 调用 UserSessionUnit.TIWUserSession 的验证函数}
function TIWServerController.IWAutherEvent1Check(const aUser, aPass: string): Boolean;
begin
  Result := UserSession.MyCheck(aUser, aPass);
end;

{OnCreate 事件, 这个关联可以在设计时做}
procedure TIWServerController.IWServerControllerBaseCreate(Sender: TObject);
begin
  Auther := IWAutherEvent1;
end;

procedure TIWServerController.IWServerControllerBaseNewSession(ASession: TIWApplication);
begin
  ASession.Data := TIWUserSession.Create(nil, ASession);
end;

initialization

TIWServerController.SetServerControllerClass;

end.