login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > GD library > Random image password generator

Random image password generator

Auteur: Tri - 08 januari 2005 - 15:04 - Gekeurd door: Dennisvb - Hits: 10112 - Aantal punten: 4.17 (3 stemmen)




Alles spreekt voor zich denk ik, lees anders de broncode.

Veel plezier ermee!

Tri

Code:
  1. <?php
  2. /*
  3. October 2004
  4. *** Random Image-Password Generator ***
  5. This script generates a random string, displayed
  6. on an image.
  7.  
  8. It can be very useful to prevent bots from automatic
  9. logins or sign-ups.
  10.  
  11. Example:
  12. You have a form and you want to be sure that no bots
  13. automatically sign-up to gain e.g. extra credit.
  14. To prevent this, let the user type the 'random' string,
  15. that is displayed on the image, in a field. When this is
  16. correct, you're sure that it's a human filling in :)
  17.  
  18. NOTE: You need to have GD library installed!!!
  19.  
  20.  
  21. by Tri Pham
  22. www.tripham.nl
  23. tri[at]tripham.nl
  24. */
  25.  
  26.  
  27. $width = 200; // width of image
  28. $height = 80; // height of image
  29. $len = 10; // length of string
  30. $fontsize = 5; // fontsize
  31.  
  32. unset($random_text);
  33.  
  34. $lchar = 0;
  35. $char = 0;
  36. /**************************************************
  37. $random_text will hold the secret and random text!
  38. **************************************************/
  39. // create 'random' text
  40. for($i = 0; $i < $len; $i++) {
  41. while($char == $lchar) {
  42. $char = rand(48, 109);
  43. if($char > 57) $char += 7;
  44. if($char > 90) $char += 6;
  45. }
  46. $random_text .= chr($char);
  47. $lchar = $char;
  48. }
  49.  
  50. $fontwidth = ImageFontWidth($fontsize) * strlen($random_text);
  51. $fontheight = ImageFontHeight($fontsize);
  52.  
  53. // create handle for image
  54. $im = @imagecreate($width,$height);
  55.  
  56. // white background
  57. $background_colour = imagecolorallocate($im, 255, 255, 255);
  58.  
  59. // give the 'random' text a nice colour
  60. $text_colour = imagecolorallocate($im, rand(0,100), rand(0,100), rand(0,100));
  61.  
  62. // give the border a colour too ;)
  63. imagerectangle($im, 0, 0, $width-1, $height-1, $text_colour);
  64.  
  65. // draw the string horizontally
  66. imagestring($im, $fontsize, rand(3, $width-$fontwidth-3), rand(2, $height-$fontheight-3), $random_text, $text_colour);
  67.  
  68. // lets output!
  69. header("Content-type: image/png");
  70. imagepng($im,'',80);
  71.  
  72. imagedestroy($im);
  73. ?>
Download code! Download code (.txt)

 Bekijk een voorbeeld van dit script!
 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (4)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.023s