forked from ZwiiCMS-Team/ZwiiCMS
Merge branch '10400' into data_engine
This commit is contained in:
commit
2f27ca0235
@ -50,55 +50,61 @@ class template {
|
|||||||
'limit' => false
|
'limit' => false
|
||||||
], $attributes);
|
], $attributes);
|
||||||
|
|
||||||
// Tirage de l'opération et des nombres
|
// Captcha quatre opérations
|
||||||
// Correspondance tableau des images
|
// Limite addition et soustraction selon le type de captcha
|
||||||
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
|
$numbers = [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 = ['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;
|
||||||
|
|
||||||
// Détermination de la limitation
|
// Tirage de l'opération
|
||||||
$limit = $attributes['limit'] ? count($letters)-1 : 10;
|
mt_srand((float) microtime()*1000000);
|
||||||
mt_srand((float) microtime()*1000000);
|
$operator = mt_rand (1, 4);
|
||||||
$operator = mt_rand (0, 3);
|
|
||||||
|
|
||||||
// Limiter les valuers si pas une addition
|
// Limite si multiplication ou division
|
||||||
if ($operator > 1) $limit = 10;
|
if ($operator > 2) {
|
||||||
$firstNumber = mt_rand (1, $limit);
|
$limit = 10;
|
||||||
$secondNumber = mt_rand (1, $limit);
|
|
||||||
|
|
||||||
// Ordre des valeurs selon type d'opération
|
|
||||||
if (($operator < 2) AND ($firstNumber < $secondNumber)) {
|
|
||||||
$temp = $firstNumber;
|
|
||||||
$firstNumber = $secondNumber;
|
|
||||||
$secondNumber = $temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calcul du résultat et icône de l'opérateur
|
// Tirage des nombres
|
||||||
switch ($operator) {
|
mt_srand((float) microtime()*1000000);
|
||||||
case 0:
|
$firstNumber = mt_rand (1, $limit);
|
||||||
$operator = template::ico('plus');
|
mt_srand((float) microtime()*1000000);
|
||||||
$result = $firstNumber + $secondNumber;
|
$secondNumber = mt_rand (1, $limit);
|
||||||
break;
|
|
||||||
case 1:
|
// Permutation si addition ou soustraction
|
||||||
$operator = template::ico('minus');
|
if (($operator < 3) and ($firstNumber < $secondNumber)) {
|
||||||
$result = $firstNumber - $secondNumber;
|
$temp = $firstNumber;
|
||||||
break;
|
$firstNumber = $secondNumber;
|
||||||
case 2:
|
$secondNumber = $temp;
|
||||||
$operator = template::ico('cancel');
|
|
||||||
$result = $firstNumber * $secondNumber;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$operator = template::ico('divide');
|
|
||||||
$limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2];
|
|
||||||
for ($i = 1; $i <= $firstNumber; $i++) {
|
|
||||||
$limit = $limit2[$i-1];
|
|
||||||
}
|
|
||||||
mt_srand((float) microtime()*1000000);
|
|
||||||
$secondNumber = mt_rand(1, $limit);
|
|
||||||
$firstNumber = $firstNumber * $secondNumber;
|
|
||||||
$result = $firstNumber / $secondNumber;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Icône de l'opérateur et calcul du résultat
|
||||||
|
switch ($operator) {
|
||||||
|
case 1:
|
||||||
|
$operator = template::ico('plus');
|
||||||
|
$result = $firstNumber + $secondNumber;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$operator = template::ico('minus');
|
||||||
|
$result = $firstNumber - $secondNumber;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$operator = template::ico('cancel');
|
||||||
|
$result = $firstNumber * $secondNumber;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$operator = template::ico('divide');
|
||||||
|
$limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2];
|
||||||
|
for ($i = 1; $i <= $firstNumber; $i++) {
|
||||||
|
$limit = $limit2[$i-1];
|
||||||
|
}
|
||||||
|
mt_srand((float) microtime()*1000000);
|
||||||
|
$secondNumber = mt_rand(1, $limit);
|
||||||
|
$firstNumber = $firstNumber * $secondNumber;
|
||||||
|
$result = $firstNumber / $secondNumber;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Hashage du résultat
|
// Hashage du résultat
|
||||||
$result = password_hash($result, PASSWORD_BCRYPT);
|
$result = password_hash($result, PASSWORD_BCRYPT);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user