From afea6188673d22d1511daeb97c5e81a2eb578c82 Mon Sep 17 00:00:00 2001 From: slawkens Date: Tue, 31 May 2022 15:13:59 +0200 Subject: [PATCH] Optimize code (account number generation) Thanks kamil-karkus for suggestion --- common.php | 3 +++ system/pages/createaccount.php | 2 +- tools/generate_account_number.php | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/common.php b/common.php index 2f14939e..f0927d6b 100644 --- a/common.php +++ b/common.php @@ -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(); diff --git a/system/pages/createaccount.php b/system/pages/createaccount.php index 4a8d3f69..06f5f414 100644 --- a/system/pages/createaccount.php +++ b/system/pages/createaccount.php @@ -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); diff --git a/tools/generate_account_number.php b/tools/generate_account_number.php index 6529f485..a53ba9a3 100644 --- a/tools/generate_account_number.php +++ b/tools/generate_account_number.php @@ -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);