Skip to content

Instantly share code, notes, and snippets.

@afiqiqmal
Last active January 25, 2021 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afiqiqmal/99cd3195f1fb79846d4f788505c1ecad to your computer and use it in GitHub Desktop.
Save afiqiqmal/99cd3195f1fb79846d4f788505c1ecad to your computer and use it in GitHub Desktop.
TwoFactorAuthenticationProvider
<?php
class TwoFactorAuthenticationProvider
{
protected $engine;
public function __construct(Google2FA $engine)
{
$this->engine = $engine;
}
public function generateSecretKey()
{
return $this->engine->generateSecretKey();
}
public function generateRecoveryCodes($times = 8, $random = 10)
{
return Collection::times($times, function () {
return Str::random($random).'-'.Str::random($random);
})->toArray();
}
public function qrCodeUrl(string $companyName, string $companyEmail, string $secret)
{
return $this->engine->getQRCodeUrl($companyName, $companyEmail, $secret);
}
public function verify(string $secret, string $code)
{
return $this->engine->verifyKey($secret, $code);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment