Test Foro de elhacker.net SMF 2.1

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 (php) [Seleccionar]

<?php
function crearCaptcha($largo 8){
    
$captcha imagecreatefromgif("bg.gif");
    
$posicionX=15;
    for(
$i 0;$i <$largo;$i++){
        
$r=rand(0,255);
        
$g=rand(0,255);
        
$b=rand(0,255);
        
$numero rand(0,9);
        
$posicionY=rand(20,40);
        
$colorText imagecolorallocate($captcha$r$g$b);
        
imagestring($captcha12$posicionX$posicionY$numero$colorText);
        
$posicionX+=15;
    }
    
$black ImageColorAllocate($captcha,0,0,0);
    
ImageFill($captcha,0,0,$black);
    
ImageColorTransparent($captcha,$black);
    
$superponer imagecreatefromgif("sub.gif"); 
    
imagecopy$captcha$superponer0000imagesx$superponer ), imagesy$superponer ) );
   
    
header("Content-type: image/gif");
    
imagegif($captcha);

}
crearCaptcha();
?>



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
Cita de: 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

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
Cita de: dark_sargon en 23 Diciembre 2011, 16:58 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
Cita de: 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...

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 (php) [Seleccionar]

<?php
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: GIFEncoder Version 2.0 by László Zsidi, http://gifs.hu
::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/
include "GIFEncoder.class.php";

class 
Captcha
{
protected $captcha;
protected $clave;

function __construct()
{
$rnd rand(01000000);
$key strtoupper(substr(md5microtime() * $rnd),1,5));
$this->clave $key;
$this->captcha imagecreatefromgif('bg.gif');
$posicion_x=15;
for($i 0;$i<strlen($key);$i++){
$r=rand(0,255);
$g=rand(0,255);
$b=rand(0,255);
$posicion_y=rand(20,40);
$colorText imagecolorallocate($this->captcha$r$g$b);
imagestring($this->captcha30$posicion_x$posicion_y$key[$i], $colorText);
$posicion_x+=25;
}
//Fix con el color de la segunda letra
$white ImageColorAllocate($this->captcha,0,0,0);
ImageColorTransparent($this->captcha,$white);
}

public function imprimir()
{
if (!empty($this->frames) AND !empty($this->framed))
{
$gif = new GIFEncoder($this->frames$this->framed02000'url');
Header ('Content-type:image/gif');
echo $gif->GetAnimation();
imagedestroy($this->captcha);
}else{
Header('Content-type:image/gif');
imagegif($this->captcha);
}

}

public function guardar()
{
$_SESSION['CAPTCHA_TEXT'] = $this->clave;
return $this->clave;
}
}

class 
Animacion extends Captcha
{
public $frames;
public $framed;

function __construct($aleatorio 1)
{
parent::__construct();
if ($aleatorio == 1) {
$n rand(1,3);
$n == $this->circulo() : 'no' ;
$n == $this->bum() : 'no' ;
$n == $this->desliz() : 'no' ;
}
}

public function circulo()
{
$circulo_x 40;
$circulo_y 0;
$frames_x 20;
for($b=0;$b<$frames_x;$b++){
$im imagecreatetruecolor(15080);
imagecopy($im$this->captcha0000imagesx($this->captcha), imagesy($this->captcha));
//fix
$white ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
$circulo imagecolorallocate($im000);
imagefilledellipse$im$circulo_y$circulo_x3030$circulo );
$fname 'tmp/'.$b.'.gif';
imagegif($im$fname);
$this->frames[] = $fname;
$this->framed[] = 1;
$circulo_y+=10;
imagedestroy($im);
}
$this->imprimir();
}

public function bum()
{
$frames_x 30;
for($b=0;$b<$frames_x;$b++){
$im imagecreatetruecolor(15080);
imagecopy($im$this->captcha0000imagesx($this->captcha), imagesy($this->captcha));
//fix
$white ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
imagefilledrectangle($im,($b*5),($b*5),10+($b*5),10+($b*5),0);
imagefilledrectangle($im,($b*1),($b*5),10+($b*1),10+($b*5),0);
imagefilledrectangle($im,($b*3)*2,($b*1)+$b,10+($b*3)*2,10+($b*1)+$b,0);
imagefilledrectangle($im,($b*4)*2,($b*2)+$b,10+($b*4)*2,10+($b*2)+$b,0);
$fname 'tmp/'.$b.'.gif';
imagegif($im$fname);
$this->frames[] = $fname;
$this->framed[] = 1;
imagedestroy($im);
}
$this->imprimir();
}

public function desliz()
{
$imgwidth imagesx($this->captcha);
$imgheight imagesy($this->captcha);
$frames_x 30;
for($b=0;$b<$frames_x;$b++){
$im imagecreatetruecolor(15080);
imagecopy($im$this->captcha0000imagesx($this->captcha), imagesy($this->captcha));
//fix
$white ImageColorAllocate($im,255,255,255);
ImageFill($im,0,0,$white);
imagefilledrectangle($im,($b 1) * 8,1,$imgwidth,$imgheight0);
$fname 'tmp/'.$b.'.gif';
imagegif($im$fname);
$this->frames[] = $fname;
$this->framed[] = 1;
imagedestroy($im);
}
$this->imprimir();
}
}

// Animacion aleatoria
$showtime = new Animacion();
//$showtime->guardar();

// Seleccionar animacion
//$showtime = new Animacion(0);
//$showtime->bum();

// Sin animacion
//$showtime = new Captcha();
//$showtime->imprimir();

?>