Fixed code generator
This commit is contained in:
parent
fbd5835bd9
commit
9b897629ba
2 changed files with 8 additions and 2 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue