-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGS.Common.OneTimePassword.Default.pas
More file actions
49 lines (39 loc) · 1.02 KB
/
GS.Common.OneTimePassword.Default.pas
File metadata and controls
49 lines (39 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
unit GS.Common.OneTimePassword.Default;
interface
uses sysutils
,classes
,GS.Common.OneTimePassword
,Base32U
,GoogleOTP;
Type
TGSOPTSha1TimeBased = class(TInterfacedObject, IGSOTP)
private
FWindowRange: byte;
FTokenLen: byte;
public
constructor Create; virtual;
function validate(secret : string; token : String) : boolean;
function generate(secret : string) : String;
property ValidationWindowRangeInSec : byte read FWindowRange write FWindowRange;
property tokenLen : byte read FTokenLen write FTokenLen;
end;
implementation
{ TGSOPTSha1TimeBased }
constructor TGSOPTSha1TimeBased.Create;
begin
inherited;
FWindowRange := 4;
FTokenLen := 6;
end;
function TGSOPTSha1TimeBased.generate(secret: string): String;
begin
result := IntToStr(CalculateOTP(secret,-1,FTokenLen));
end;
function TGSOPTSha1TimeBased.validate(secret, token: String): boolean;
var li : integer;
begin
li := StrToIntDef(token,0);
Assert(li>0);
result := ValidateTOPTTimeBased(secret,li,FWindowRange,FTokenLen);
end;
end.