Download the PHP package khooz/oath without Composer
On this page you can find all versions of the php package khooz/oath. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package oath
Short Description The TOTP based on [RFC6238](https://tools.ietf.org/html/rfc6238)
License MIT
Informations about the package oath
Oath
Oath is a One Time Password library used in authenticators. It covers both HOTP and TOTP methods of code generation.
What is this package?
It implements the HMAC-based One-Time Password specified in RFC6238 used in many Two Step Authentication solutions. It is compatible with Authenticator Apps Like Google's and Microsoft's. It uses a @devicenull 's class called Base32 for RFC3548 Base32 encodeing and decoding. Feel free to use any custom Base32-converting class, which have encode
and decode
public static functions.
Getting Started
This package uses PSR-4 autoloading which eases the installation and use with major framework or any projects utilising composer. Simply use composer to install this package as your project's dependency:
Usage
You can simply use the default parameters of this package to generate or check HMAC-based One-Time Passwords:
You can also customize the default parameters using config
static method before instantiating the Oath
class, or after, for the newer instantiations.
One instantiated, the Oath
object encapsulates all the data it needs for a single user and defaults can safely be changed for furthur users.
Methods
Oath::generate(int $pivot)
Generates a new code based on object parameter. By using $pivot, you can go back and forth with codes and generate expired codes (negative value) or coming codes (positive value). You will get the current valid code when $pivot = 0
(default behaviour).
Oath::check(int $code, int $rabge, int $pivot)
Checks an n-digit, integer $code
with a telorance of $range
around a $pivot
point in codes sequence.
Properties
All non-static properties of Oath
is accessible through it's name's __get
and __set
invocations; though there are some important properties and some virtual properties woth mentioning. I encourage you to see the Oath
class in detail.
Oath::secret
Along with Oath::message
and Oath::salt
, the secret or the other two (which make the secret if they are present) define an instance for authentication. You should exchange the secret to the user to store so you could generate the same codes sequence to compare against. You should also store either the secret, or the message & salt. The secret is a binary string represented in Base32 encoding.
Oath::message
and Oath::salt
You either introduce a Base32 secret, or make one using a message and a salt. if you don't provide either, a randomly generated message and salt will generate a secret for you.
Oath->uri
This is a virtual property which will give you an otpauth
URL-encoded URI, so you could use a QR-code or a link to exchange authentication token instances with user.
It is formatted as bellow:
The parameters
are secret
, digits
, algorithm
, period
or counter
in URL-encoded HTTP Query format.
Special Thanks goes to
- [email protected] for this article
- Wikipedia.org for this article
- @devicenull for this class
finally()
{
And if you feel like it, you can donate here to help me.
}