Skip to content

Commit a1bbf90

Browse files
committed
fixing
1 parent cccb479 commit a1bbf90

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Totp/GoogleTotp.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
class GoogleTotp
66
{
7-
public static function generateSecret(int $length = 20): string
7+
public static function generateSecret(int $length = 16): string
88
{
9-
$randomBytes = random_bytes($length);
10-
return rtrim(strtr(base64_encode($randomBytes), '+/', 'AB'), '=');
9+
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
10+
$secret = '';
11+
$alphabetLength = strlen($alphabet);
12+
13+
for ($i = 0; $i < $length; $i++) {
14+
$secret .= $alphabet[random_int(0, $alphabetLength - 1)];
15+
}
16+
17+
return $secret;
1118
}
1219

1320
public static function buildOtpAuthUrl(string $secret, string $label, string $issuer, int $digits = 6, int $period = 30): string

0 commit comments

Comments
 (0)