TOTP-Hack
TOTP-Hack is an implementation of Time-Based One-Time Password Algorithm in HackLang. It is compatible with Google Authenticator app and similar apps. It has a super-simple API and allows you to even generate QR codes for your ease.
API
namespace raeesbhatti;
class TOTP {
public static function getInstance(string $Secret, string $Type = 'remote'): this
public function generate(?float $Time = null): string
public function generateQRCode(string $Title, string $Issuer, int $Size = 250): string
public function verify(string $Key): bool
}
Examples
$Auth = raeesbhatti\TOTP::getInstance('SomeSecretUserSpecificKey');
$Key = $Auth->generate();
$Valid = $Auth->verify($Key);
echo "Key: $Key\n";
echo "Valid: $Valid\n";
Here is how to get a Google Charts image URL for your QR Code:
$Auth = raeesbhatti\TOTP::getInstance('SomeSecretUserSpecificKey');
echo $Auth->generateQRCode("user@example.com", "My Website");
or you can generate the image locally after installing qrencode
, here is how:
$Auth = raeesbhatti\TOTP::getInstance('SomeSecretUserSpecificKey', 'local');
header('Content-Type: image/png');
echo $Auth->generateQRCode("user@example.com", "My Website");
License and Credits
This project is licensed under the terms of MIT License. It was derived from steelbrain/Google-Authenticator.