* Sample to demonstrate generating/showing/checking a TOTP

This commit is contained in:
Michaël Van Canneyt 2022-01-28 11:37:19 +01:00
parent d5d9716916
commit 2391d317bc

View File

@ -0,0 +1,33 @@
{$mode objfpc}
{$h+}
uses sysutils, onetimepass;
Var
aCount : Longint;
begin
If ParamCount=0 then
Writeln('New key: ',TOTPSharedSecret)
else If ParamCount=1 then
begin
if (ParamStr(1)='-h') or (ParamStr(1)='--help') then
begin
Writeln('Usage : ',ExtractFileName(Paramstr(0)),' [key [code]]');
Writeln('If no options are specified, generate key');
Writeln('If only key is specified, print current code');
Writeln('If both key and code are specified then check code');
end
else
Writeln('Current token : ',TOTPGenerateToken(ParamStr(1)));
end
else
begin
if TOTPValidate(Paramstr(1),StrToIntDef(ParamStr(2),-1),1,aCount) then
Writeln('Code OK')
else
begin
Writeln('Code wrong');
ExitCode:=1;
end;
end;
end.