Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: peib0l en 20 Diciembre 2011, 13:41 pm



Título: captchas
Publicado por: peib0l en 20 Diciembre 2011, 13:41 pm
hola amigos, estoy con el tema de los captcha y me preguntaba como se hacen estos

(http://linksave.in/captcha/cap.php?hsh=a90f26a&code=6651988384eef647a5af45)

y la otra pregunta es como se implementan los captcha ya creados como el de google?

Gracias!


Título: Re: captchas
Publicado por: [u]nsigned en 20 Diciembre 2011, 14:32 pm
Podes usar reCaptcha (https://www.google.com/recaptcha/admin/create)(el mas comun) que es de Google, es por ejemplo, lo que usa el host de imagenes (http://i.elhacker.net) de este foro.

Saludos


Título: Re: captchas
Publicado por: EFEX en 22 Diciembre 2011, 18:06 pm
Traté de hacer un script pero creo que la libreria GD no soporta animaciones gif?

Código
  1. <?php
  2. function crearCaptcha($largo = 8){
  3.    $captcha = imagecreatefromgif("bg.gif");
  4.    $posicionX=15;
  5.    for($i = 0;$i <$largo;$i++){
  6.        $r=rand(0,255);
  7.        $g=rand(0,255);
  8.        $b=rand(0,255);
  9.        $numero = rand(0,9);
  10.        $posicionY=rand(20,40);
  11.        $colorText = imagecolorallocate($captcha, $r, $g, $b);
  12.        imagestring($captcha, 12, $posicionX, $posicionY, $numero, $colorText);
  13.        $posicionX+=15;
  14.    }
  15.    $black = ImageColorAllocate($captcha,0,0,0);
  16.    ImageFill($captcha,0,0,$black);
  17.    ImageColorTransparent($captcha,$black);
  18.    $superponer = imagecreatefromgif("sub.gif");
  19.    imagecopy( $captcha, $superponer, 0, 0, 0, 0, imagesx( $superponer ), imagesy( $superponer ) );
  20.  
  21.    header("Content-type: image/gif");
  22.    imagegif($captcha);
  23.  
  24. }
  25. crearCaptcha();
  26. ?>
  27.  

Animación
(http://oi44.tinypic.com/w86puq.jpg)
Fondo
(http://i39.tinypic.com/auvrs_th.gif)

Resultado  :¬¬

(http://oi42.tinypic.com/178epw.jpg)


Título: Re: captchas
Publicado por: dark_sargon en 22 Diciembre 2011, 22:05 pm
http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html


Título: Re: captchas
Publicado por: Anonymous250 en 23 Diciembre 2011, 04:40 am
Anda asi que ese captcha se hace on un gif que interesante. :)


Título: Re: captchas
Publicado por: EFEX en 23 Diciembre 2011, 15:13 pm
http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html

Pero ¿ debo primero tomar los frames animados, ponerle de fondo el captcha a cada uno, gardarlos por frame y despues unirlos con la clase ?
Veo que tiene problemas con la transparencia y la animacion..
(http://oi42.tinypic.com/24gimip.jpg)

v3.0 gifencoder (https://code.google.com/p/phpvideotoolkit/source/browse/trunk/phpvideotoolkit/adapters/ffmpeg-php/gifencoder/?r=6)


Título: Re: captchas
Publicado por: dark_sargon en 23 Diciembre 2011, 16:58 pm
Encontré un script ya hecho. Lo que hace es crear todos los frames en la carpeta 'tmp' y luego construye el GIF y los borra.

Se podría hacer aleatoria la animación para que no sea la misma siempre.
(http://actimediaonline.com/captchaGIF/imgCaptcha.php)

A ver si nos ponemos en la tarea de mejorar la apariencia. Éste tema de las CAPTCHAs es muy interesante.

Acá el script junto con la clase GIFEncoder:
http://www.actimediaonline.com/captchaGIF.zip (http://www.actimediaonline.com/captchaGIF.zip)


Título: Re: captchas
Publicado por: EFEX en 23 Diciembre 2011, 20:05 pm
Acá el script junto con la clase GIFEncoder:
http://www.actimediaonline.com/captchaGIF.zip (http://www.actimediaonline.com/captchaGIF.zip)

No me crea el gif por que no me guarda las imagenes en la carpeta tmp ¿por que ?


Título: Re: captchas
Publicado por: peib0l en 9 Enero 2012, 13:38 pm
Alguno a sacado ya como hacerlos en movimiento?  :P yo sigo en ello pero no se mueve...


Título: Re: captchas
Publicado por: EFEX en 10 Enero 2012, 07:52 am
Alguno a sacado ya como hacerlos en movimiento?  :P yo sigo en ello pero no se mueve...

Es crear varios frames, como un gif con un circulo, cuadrado, lo que sea (hacerlo aleatorio) que tape parte del captcha y despues unirlos con el script que menciona dark_sargon, el problema que tenia es que no me guarda la imagen creada en el archivo tmp(es el mismo script que aconseja dark_sargon), haber si alguien me ayuda asi seguimos con esto  ;).


Título: Re: captchas
Publicado por: EFEX en 3 Febrero 2012, 12:07 pm
Version de GIFEncoder que utilizé PHPclasses (http://www.phpclasses.org/browse/file/17972.html) / Pastie Bin (http://pastiebin.com/?page=p&id=4f2bbdb039534).
Código
  1. <?php
  2. /*
  3. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  4. ::
  5. :: GIFEncoder Version 2.0 by László Zsidi, http://gifs.hu
  6. ::
  7. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  8. */
  9. include "GIFEncoder.class.php";
  10.  
  11. class Captcha
  12. {
  13. protected $captcha;
  14. protected $clave;
  15.  
  16. function __construct()
  17. {
  18. $rnd = rand(0, 1000000);
  19. $key = strtoupper(substr(md5( microtime() * $rnd),1,5));
  20. $this->clave = $key;
  21. $this->captcha = imagecreatefromgif('bg.gif');
  22. $posicion_x=15;
  23. for($i = 0;$i<strlen($key);$i++){
  24. $r=rand(0,255);
  25. $g=rand(0,255);
  26. $b=rand(0,255);
  27. $posicion_y=rand(20,40);
  28. $colorText = imagecolorallocate($this->captcha, $r, $g, $b);
  29. imagestring($this->captcha, 30, $posicion_x, $posicion_y, $key[$i], $colorText);
  30. $posicion_x+=25;
  31. }
  32. //Fix con el color de la segunda letra
  33. $white = ImageColorAllocate($this->captcha,0,0,0);
  34. ImageColorTransparent($this->captcha,$white);
  35. }
  36.  
  37. public function imprimir()
  38. {
  39. if (!empty($this->frames) AND !empty($this->framed))
  40. {
  41. $gif = new GIFEncoder($this->frames, $this->framed, 0, 2, 0, 0, 0, 'url');
  42. Header ('Content-type:image/gif');
  43. echo $gif->GetAnimation();
  44. imagedestroy($this->captcha);
  45. }else{
  46. Header('Content-type:image/gif');
  47. imagegif($this->captcha);
  48. }
  49.  
  50. }
  51.  
  52. public function guardar()
  53. {
  54. $_SESSION['CAPTCHA_TEXT'] = $this->clave;
  55. return $this->clave;
  56. }
  57. }
  58.  
  59. class Animacion extends Captcha
  60. {
  61. public $frames;
  62. public $framed;
  63.  
  64. function __construct($aleatorio = 1)
  65. {
  66. parent::__construct();
  67. if ($aleatorio == 1) {
  68. $n = rand(1,3);
  69. $n == 1 ? $this->circulo() : 'no' ;
  70. $n == 2 ? $this->bum() : 'no' ;
  71. $n == 3 ? $this->desliz() : 'no' ;
  72. }
  73. }
  74.  
  75. public function circulo()
  76. {
  77. $circulo_x = 40;
  78. $circulo_y = 0;
  79. $frames_x = 20;
  80. for($b=0;$b<$frames_x;$b++){
  81. $im = imagecreatetruecolor(150, 80);
  82. imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
  83. //fix
  84. $white = ImageColorAllocate($im,255,255,255);
  85. ImageFill($im,0,0,$white);
  86. $circulo = imagecolorallocate($im, 0, 0, 0);
  87. imagefilledellipse( $im, $circulo_y, $circulo_x, 30, 30, $circulo );
  88. $fname = 'tmp/'.$b.'.gif';
  89. imagegif($im, $fname);
  90. $this->frames[] = $fname;
  91. $this->framed[] = 1;
  92. $circulo_y+=10;
  93. }
  94. $this->imprimir();
  95. }
  96.  
  97. public function bum()
  98. {
  99. $frames_x = 30;
  100. for($b=0;$b<$frames_x;$b++){
  101. $im = imagecreatetruecolor(150, 80);
  102. imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
  103. //fix
  104. $white = ImageColorAllocate($im,255,255,255);
  105. ImageFill($im,0,0,$white);
  106. imagefilledrectangle($im,($b*5),($b*5),10+($b*5),10+($b*5),0);
  107. imagefilledrectangle($im,($b*1),($b*5),10+($b*1),10+($b*5),0);
  108. imagefilledrectangle($im,($b*3)*2,($b*1)+$b,10+($b*3)*2,10+($b*1)+$b,0);
  109. imagefilledrectangle($im,($b*4)*2,($b*2)+$b,10+($b*4)*2,10+($b*2)+$b,0);
  110. $fname = 'tmp/'.$b.'.gif';
  111. imagegif($im, $fname);
  112. $this->frames[] = $fname;
  113. $this->framed[] = 1;
  114. }
  115. $this->imprimir();
  116. }
  117.  
  118. public function desliz()
  119. {
  120. $imgwidth = imagesx($this->captcha);
  121. $imgheight = imagesy($this->captcha);
  122. $frames_x = 30;
  123. for($b=0;$b<$frames_x;$b++){
  124. $im = imagecreatetruecolor(150, 80);
  125. imagecopy($im, $this->captcha, 0, 0, 0, 0, imagesx($this->captcha), imagesy($this->captcha));
  126. //fix
  127. $white = ImageColorAllocate($im,255,255,255);
  128. ImageFill($im,0,0,$white);
  129. imagefilledrectangle($im,($b - 1) * 8 + 8,1,$imgwidth,$imgheight, 0);
  130. $fname = 'tmp/'.$b.'.gif';
  131. imagegif($im, $fname);
  132. $this->frames[] = $fname;
  133. $this->framed[] = 1;
  134. }
  135. $this->imprimir();
  136. }
  137. }
  138.  
  139. // Animacion aleatoria
  140. $showtime = new Animacion();
  141. //$showtime->guardar();
  142.  
  143. // Seleccionar animacion
  144. //$showtime = new Animacion(0);
  145. //$showtime->bum();
  146.  
  147. // Sin animacion
  148. //$showtime = new Captcha();
  149. //$showtime->imprimir();
  150.  
  151. ?>
  152.