Git Product home page Git Product logo

delphiotp's Introduction

OTP for Delphi

Google Authenticator is based on RFC 4226 - a Time based One Time Password (TOTP) which is initialised using a 16 digit base 32 (RFC 4648) encoded seed value. Initial seeds used for the TOTP can be entered into the Google Authenticator via a camera using QR codes or via the keyboard.

This Repository contains the working functions and all dependencies to either create a token generator or to validate tokens.

Base32-Unit

The code in previous versions of the Base32U.pas was not even close to being unicode ready. If you found this repository while looking for a working Base32 Implementation in Delphi, please have a look at SZCodeBaseX. To have that one working in Delphi XE2 and higher, you will have to replace all String-Arguments with AnsiString ones.

How to generate Time-based OTP using the code provided?

MYBASE32SECRET is the pre-shared secret.

uses
  GoogleOTP;
  
[...]

var
	Token: Integer;
begin
	// Using time-based Token
	Token := CalculateOTP('MYBASE32SECRET'); // Returns the Token as Integer;

	// To display the token, use the Format-Function
	ShowMessage(Format('%.6d', [Token]));
end;

How to generate Counter-based OTP using the code provided?

MYBASE32SECRET is the pre-shared secret. 4 is an example value from the counter

uses
  GoogleOTP;
  
[...]

var
	Token: Integer;
begin
	// Using counter-based Token
	Token := CalculateOTP('MYBASE32SECRET', 4); // Returns the Token as Integer;

	// To display the token, use the Format-Function
	ShowMessage(Format('%.6d', [Token]));
end;

How to validate Time-based OTP using the code provided?

uses
  GoogleOTP;
  
[...]

var
	Token: Integer;
begin
	// Ask the user for a token
	Token := 123456;
	
	// Check the Token
	if (ValidateTOPT('MYBASE32SECRET', Token)) then
		ShowMessage('Access granted')
	else
		ShowMessage('Access denied');
end;

License

This repository is licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.