Optimisation captcha

This commit is contained in:
fredtempez 2020-10-28 19:36:23 +01:00
parent 8833dca44f
commit 5de144f947

View File

@ -49,66 +49,58 @@ class template {
'value' => '', 'value' => '',
'limit' => false 'limit' => false
], $attributes); ], $attributes);
// Génération des nombres et choix de l'opération // Tirage de l'opération et des nombres
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20); $numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
$letters = array('u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'); $letters = array('u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a');
$limit = $attributes['limit'] ? count($letters)-1 : 10; $limit = $attributes['limit'] ? count($letters)-1 : 10;
mt_srand((float) microtime()*1000000); mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, $limit);
mt_srand((float) microtime()*1000000);
$secondNumber = mt_rand (1, $limit);
mt_srand((float) microtime()*1000000);
$operator = mt_rand (0, 3); $operator = mt_rand (0, 3);
switch ($operator) { if ($operator > 1) {
case 0: $limit = 10;
$operator = template::ico('plus'); }
if ($firstNumber < $secondNumber) { $firstNumber = mt_rand (1, $limit);
$secondNumber = mt_rand (1, $limit);
if ( ($operator < 2)
AND ($firstNumber < $secondNumber) )
{
$temp = $firstNumber; $temp = $firstNumber;
$firstNumber = $secondNumber; $firstNumber = $secondNumber;
$secondNumber = $temp; $secondNumber = $temp;
} }
switch ($operator) {
case 0:
$operator = template::ico('plus');
$result = $firstNumber + $secondNumber; $result = $firstNumber + $secondNumber;
break; break;
case 1: case 1:
$operator = template::ico('minus'); $operator = template::ico('minus');
if ($firstNumber < $secondNumber) {
$temp = $firstNumber;
$firstNumber = $secondNumber;
$secondNumber = $temp;
}
$result = $firstNumber - $secondNumber; $result = $firstNumber - $secondNumber;
break; break;
case 2: case 2:
$operator = template::ico('cancel'); $operator = template::ico('cancel');
mt_srand((float) microtime()*1000000);
$firstNumber = mt_rand (1, 10);
mt_srand((float) microtime()*1000000);
$secondNumber = mt_rand (1, 10);
$result = $firstNumber * $secondNumber; $result = $firstNumber * $secondNumber;
break; break;
case 3: case 3:
$operator = template::ico('divide'); $operator = template::ico('divide');
mt_srand((float) microtime()*1000000); switch ($firstNumber) {
$firstNumber = mt_rand (1, 10); case 3:
mt_srand((float) microtime()*1000000); $limit = 6;
if ($firstNumber < 3) { break;
$secondNumber = mt_rand(1, 10); case 4:
} $limit = 5;
elseif ($firstNumber = 3) { break;
$secondNumber = mt_rand(1, 6); case 5:
} $limit = 4;
elseif ($firstNumber = 4) { break;
$secondNumber = mt_rand(1, 5); case 6:
} $limit = 3;
elseif ($firstNumber = 5) { break;
$secondNumber = mt_rand(1, 4);
}
elseif ($firstNumber = 6 ) {
$secondNumber = mt_rand(1, 3);
}
elseif ($firstNumber > 6) {
$secondNumber = mt_rand(1, 2);
} }
if ($firstNumber > 6) $limit = 2;
$secondNumber = mt_rand(1, $limit);
$firstNumber = $firstNumber * $secondNumber; $firstNumber = $firstNumber * $secondNumber;
$result = $firstNumber / $secondNumber; $result = $firstNumber / $secondNumber;
break; break;