gentotp.pp 824 B

123456789101112131415161718192021222324252627282930313233
  1. {$mode objfpc}
  2. {$h+}
  3. uses sysutils, onetimepass;
  4. Var
  5. aCount : Longint;
  6. begin
  7. If ParamCount=0 then
  8. Writeln('New key: ',TOTPSharedSecret)
  9. else If ParamCount=1 then
  10. begin
  11. if (ParamStr(1)='-h') or (ParamStr(1)='--help') then
  12. begin
  13. Writeln('Usage : ',ExtractFileName(Paramstr(0)),' [key [code]]');
  14. Writeln('If no options are specified, generate key');
  15. Writeln('If only key is specified, print current code');
  16. Writeln('If both key and code are specified then check code');
  17. end
  18. else
  19. Writeln('Current token : ',TOTPGenerateToken(ParamStr(1)));
  20. end
  21. else
  22. begin
  23. if TOTPValidate(Paramstr(1),StrToIntDef(ParamStr(2),-1),1,aCount) then
  24. Writeln('Code OK')
  25. else
  26. begin
  27. Writeln('Code wrong');
  28. ExitCode:=1;
  29. end;
  30. end;
  31. end.