1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Fixed code generator

This commit is contained in:
Eldad Fux 2022-08-14 21:57:23 +03:00
parent fbd5835bd9
commit 9b897629ba
2 changed files with 8 additions and 2 deletions

View file

@ -293,7 +293,13 @@ class Auth
*/ */
public static function codeGenerator(int $length = 6): string public static function codeGenerator(int $length = 6): string
{ {
return substr(str_shuffle("0123456789"), 0, $length); $value = '';
for ($i = 0; $i < $length; $i++) {
$value .= random_int(0,9);
}
return $value;
} }
/** /**

View file

@ -193,7 +193,7 @@ class AuthTest extends TestCase
{ {
$this->assertEquals(6, \strlen(Auth::codeGenerator())); $this->assertEquals(6, \strlen(Auth::codeGenerator()));
$this->assertEquals(\mb_strlen(Auth::codeGenerator(256)), 256); $this->assertEquals(\mb_strlen(Auth::codeGenerator(256)), 256);
$this->assertEquals(\mb_strlen(Auth::codeGenerator(5)), 10); $this->assertEquals(\mb_strlen(Auth::codeGenerator(10)), 10);
$this->assertTrue(is_numeric(Auth::codeGenerator(5))); $this->assertTrue(is_numeric(Auth::codeGenerator(5)));
} }