Optimize code (account number generation)

Thanks kamil-karkus for suggestion
This commit is contained in:
slawkens 2022-05-31 15:13:59 +02:00
parent 0abb9384a6
commit afea618867
3 changed files with 8 additions and 5 deletions

View File

@ -86,6 +86,9 @@ const TFS_03 = 4;
const TFS_FIRST = TFS_02;
const TFS_LAST = TFS_03;
// other definitions
const ACCOUNT_NUMBER_LENGTH = 10;
session_save_path(SYSTEM . 'php_sessions');
session_start();

View File

@ -218,7 +218,7 @@ if($save)
if (!config('account_login_by_email')) {
$tmp_account = (USE_ACCOUNT_NAME ? $account_name : $account_id);
}
if($config['mail_enabled'] && $config['account_mail_verify'])
{
$hash = md5(generateRandomString(16, true, true) . $email);

View File

@ -14,15 +14,15 @@ require '../common.php';
require SYSTEM . 'functions.php';
require SYSTEM . 'init.php';
if(USE_ACCOUNT_NAME) {
if (config('account_login_by_email') || USE_ACCOUNT_NAME) {
return;
}
$hasNumberColumn = $db->hasColumn('accounts', 'number');
do {
$length = 10;
$min = (int)(1 . str_repeat(0, $length - 1));
$max = (int)str_repeat(9, $length);
$length = ACCOUNT_NUMBER_LENGTH;
$min = 10 ** ($length - 1);
$max = 10 ** $length - 1;
try {
$number = random_int($min, $max);