Changeset View
Changeset View
Standalone View
Standalone View
src/app/VerificationCode.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use App\SignupCode; | use App\SignupCode; | ||||
use Carbon\Carbon; | |||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
/** | /** | ||||
* The eloquent definition of a VerificationCode | * The eloquent definition of a VerificationCode | ||||
* | * | ||||
* @property string $mode | * @property string $mode | ||||
* @property \App\User $user | * @property \App\User $user | ||||
*/ | */ | ||||
Show All 31 Lines | class VerificationCode extends SignupCode | ||||
/** | /** | ||||
* Generate a short code (for human). | * Generate a short code (for human). | ||||
* | * | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
public static function generateShortCode(): string | public static function generateShortCode(): string | ||||
{ | { | ||||
$code_length = env('VERIFICATION_CODE_LENGTH', self::SHORTCODE_LENGTH); | $code_length = env('VERIFICATION_CODE_LENGTH', self::SHORTCODE_LENGTH); | ||||
$code_chars = env('VERIFICATION_CODE_CHARS', self::SHORTCODE_CHARS); | |||||
$random = []; | |||||
for ($i = 1; $i <= $code_length; $i++) { | return \App\Utils::randStr($code_length); | ||||
$random[] = $code_chars[rand(0, strlen($code_chars) - 1)]; | |||||
} | |||||
shuffle($random); | |||||
return implode('', $random); | |||||
} | } | ||||
} | } |