Advertisement
Guest User

CAPTCHA

a guest
Jun 15th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.  
  3. /*** Script pour générer 4 chiffres aléatoires qui seront utilisés dans un captcha ***/
  4.  
  5. $texte = "";
  6.  
  7. // On génère une séquence aléatoire
  8. $random = openssl_random_pseudo_bytes(64).md5("hI4QVLrluGbDKbVtpa4l".time()."Z0");
  9.  
  10. // On hash avec SHA512 la séquence aléatoire avec d'autres paramètres
  11. $hash = hash("SHA512","hiJ9DEZsF3hNk54VnkmM".mt_rand(0,pow(10,6)).time().$random);
  12.  
  13. // On prends les 4 premiers chiffres que l'on rencontre en parcourant le hash ($hash)
  14. for($i=0;strlen($texte)<=3;$i++)
  15. {
  16.   if(is_numeric($hash[$i]))
  17.   {
  18.     $texte .= $hash[$i]; // On ajoute à $texte le chiffre
  19.   }
  20. }
  21.  
  22. // On affiche les 4 chiffres à l'écran (qui peuvent être utilisés dans l'image d'un captcha par exemple
  23. echo $texte;
  24.  
  25. // $texte peut contenir par exemple : 8916
  26.  
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement