mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-18 17:19:32 +02:00
* Sample to demonstrate generating/showing/checking a TOTP
This commit is contained in:
parent
d5d9716916
commit
2391d317bc
33
packages/fcl-hash/examples/gentotp.pp
Normal file
33
packages/fcl-hash/examples/gentotp.pp
Normal 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.
|
Loading…
Reference in New Issue
Block a user