Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/TOTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function setAlgorithm($algorithm = 'sha1')

public static function base32Decode($in)
{
$out = '';
if (empty($in)) {
return '';
}
Expand Down Expand Up @@ -108,6 +109,7 @@ public function get($digits = 6, $period = 30, $offset = null, $now = null)

public static function genSecret($length = 32)
{
$secret = '';
if ($length < 16 || 0 != $length % 8) {
throw new \Exception('length must >= 16 || %8==0');
}
Expand All @@ -131,8 +133,11 @@ public function uri($account, $digits = null, $period = null, $issuer = null)
if (false !== mb_strpos($account.$issuer, ':')) {
throw new \Exception('cannot have colon in account / issuer');
}

$account = rawurlencode($account);
$issuer = rawurlencode($issuer);
if($issuer){
$issuer = rawurlencode($issuer);
}
$label = empty($issuer) ? $account : "{$issuer}:{$account}";

return 'otpauth://totp/'.$label."?secret={$secret}".
Expand Down