working on it ...

Filters

Explore Public Snippets

Sort by

Found 153 snippets matching: captcha

    public by azazqadir modified Jan 18, 2018  462  1  5  0

    Adding Captcha in CodeIgniter

    Source: https://www.cloudways.com/blog/captcha-in-codeigniter/
    <?php
    
    defined('BASEPATH') OR exit('your exit message');
    
    class Captcha extends CI_Controller
    
    {
    
       function __construct()
    
       {
    
           parent::__construct();
    
           $this->load->helper('captcha');
    
       }
    
       public function index()
    
       {
    
           if ($this->input->post('submit')) {
    
               $captcha_insert = $this->input->post('captcha');
    
               $contain_sess_captcha = $this->session->userdata('valuecaptchaCode');
    
               if ($captcha_insert === $contain_sess_captcha) {
    
                   echo 'Success';
    
               } else {
    
                   echo 'Failure';
    
               }
    
           }
    
           $config = array(
    
               'img_url' => base_url() . 'image_for_captcha/',
    
               'img_path' => 'image_for_captcha/',
    
               'img_height' => 45,
    
               'word_length' => 5,
    
               'img_width' => '45',
    
               'font_size' => 10
    
           );
    
           $captcha = create_captcha($config);
    
           $this->session->unset_userdata('valuecaptchaCode');
    
           $this->session->set_userdata('valuecaptchaCode', $captcha['word']);
    
           $data['captchaImg'] = $captcha['image'];
    
           $this->load->view('captcha/index', $data);
    
       }
    
       public function refresh()
    
       {
    
           $config = array(
    
               'img_url' => base_url() . 'image_for_captcha/',
    
               'img_path' => 'image_for_captcha/',
    
               'img_height' => 45,
    
               'word_length' => 5,
    
               'img_width' => '45',
    
               'font_size' => 10
    
           );
    
           $captcha = create_captcha($config);
    
           $this->session->unset_userdata('valuecaptchaCode');
    
           $this->session->set_userdata('valuecaptchaCode', $captcha['word']);
    
           echo $captcha['image'];
    
       }
    
    }

    public by paulsimmons modified Mar 28, 2017  678  0  3  0

    Canvas WordPress Plugin by FMEAddons

    Canvas WordPress plugin by FMEAddons let website owners allow their users to make drawings on the website. This plugin creates separate drawing page on the website and also enables image slider on the page. Users can make paintings on a paint book after picking any picture from image slider and they can use pen, brush, thickness selector, color
    cpp
    // Enter here the actual content of the snippet.            

    public by paulsimmons modified May 10, 2017  492  0  3  0

    Forum Magento Extension by FMEAddons

    Let the customers discuss your products in your own forum, you can create the forum by using forum Magento extension by FMEAddons. This plugin integrates the forum with your Magento e-store and allows your customers to get register on your forum. Forum extension is a good tool to engage the customers by giving them good support and you can also int
    cpp
    // Enter here the actual content of the snippet.            

    external by vulnerability.xyz Team modified Jun 26, 2015  8252  317  4  0

    root-me.org - CAPTCHA me if you can

    root-me.org - CAPTCHA me if you can: CAPTCHA.py
    # author blog : http://www.vulnerability.xyz
     # author ID : vulnerability.xyz Team
     # root-me url: http://challenge01.root-me.org/programmation/ch8/
    
    
    import urllib2, re
    import urllib, os, subprocess, time, base64
    
    opener = urllib2.build_opener()
    continue_loop = True
    while True:
        opener.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0')]
        opener.addheaders.append(('Cookie', 'challenge_frame=1; spip_session=myspip_session; PHPSESSID=myPHPSESSID'))
        opener.addheaders.append(('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'))
        opener.addheaders.append(('Accept-Language', 'en-US,en;q=0.5'))
        opener.addheaders.append(('Accept-Encoding', 'gzip, deflate'))
        opener.addheaders.append(('DNT', '1'))
        opener.addheaders.append(('Connection', 'Keep-Alive'))
        response = opener.open('http://challenge01.root-me.org/programmation/ch8/ch8.php?frame=1','')
        html = response.read()
        regex = r'data:image/png;base64,(.*)" /><br><br>'
        result = re.search(regex, html)
        result = result.group(1)
        result = base64.b64decode(result)
        file_handle = open('captcha.png', 'wb')
        file_handle.write(result)
        file_handle.close
    
        file_handle = open('captcha.png', 'rb')
        result = subprocess.Popen(['gocr -i captcha.png'], shell=True, stdout=subprocess.PIPE).communicate()[0]
        file_handle.close
        print result
        result = result.replace('\n', '')
        result = result.replace(' ', '')
        result = result.replace(',', '')
        result = result.replace('\'', '')
        print result
    
        values = {'cametu':result}
        post_data = urllib.urlencode(values)
        opener.addheaders.append(('Referer', 'http://challenge01.root-me.org/programmation/ch8/ch8.php?frame=1'))
        response = opener.open('http://challenge01.root-me.org//programmation/ch8/ch8.php?frame=1', post_data)
        file_handle = open('result.html', 'w')
        while 1:
            data = response.read()
            if not('Failed' in data) and data:
                continue_loop = False
            if not data:
                break
            file_handle.write(data)
        file_handle.close
        if continue_loop == False:
            break
    
    

    external by lidio601 modified Jun 3, 2014  219  0  3  0

    Single file PHP Captcha generator. You can use this to request a captcha image via the tag <img src="http://your.website/captcha.php" alt="captcha"> and a form to insert the captcha code. In your destination page you only have to include the same file ...

    Single file PHP Captcha generator. You can use this to request a captcha image via the tag and a form to insert the captcha code. In your destination page you only have to include the same file (with include_once('captcha.php'); ) and it will check itself if the captcha code is valid!: captcha.php
    PHP
    <?php
    
    if(!isset($_SESSION)) {
    	@session_start();
    }
    
    //debug
    //define('_JEXEC',1);
    
    //cosa faccio?
    if(defined('_JEXEC') || defined('_VALID_MOS')) {
    	$given = isset($_POST['captcha'])?$_POST['captcha']:isset($_GET['captcha'])?$_GET['captcha']:'';
    	if(isset($_SESSION['captcha']) && $_SESSION['captcha']!='' && $given !== $_SESSION['captcha']) {
    		?>
    		<script type="text/javascript">
    			alert('Errore, Ricompila questo form!');
    			history.back();
    		</script>
    		<?php
    		die('<!-- error captcha -->');
    	}
    	else {
    		//doing nothing!
    	}
    }
    else {
    	$font_file = "./arialbd.ttf";
    	$font_size = 25;
    	$length = 6;
    
    	$captcha = "";
    	$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    	$len = strlen($salt);
    	mt_srand(10000000*(double)microtime());
    	for ($i = 0; $i < $length; $i++)
    		$captcha .= $salt[mt_rand(0,$len - 1)];
    	$captcha = strtoupper($captcha);
    	$texture = imagecreatefrompng('texture.png');
    
    	$source = imagecolorat($texture, rand(0, imagesx($texture)), rand(0, imagesy($texture)));
    	$source2 = 0x94989B;
    	$r = ($source >> 16 & 0xff) + 70;
    	$g = ($source >> 8  & 0xff) + 70;
    	$b = ($source & 0xff) + 50;
    	//$r = 87; $g = 189; $b = 263;
    	$text_color = imagecolorallocate($texture, $r, $g, $b);
    	//
    	$r = ($source2 >> 16 & 0xff) + 70;
    	$g = ($source2 >> 8  & 0xff) + 70;
    	$b = ($source2 & 0xff) + 50;
    	$line_color = imagecolorallocate($texture, $r, $g, $b);
    	//87 - 189 - 263
    	$posx = 23; //imagesx($texture)/2 - strlen($captcha) * ($font_size/3);
    	$posy = imagesy($texture)/2 + $font_size/2;
    
    	//imagestring($texture, 6, (imagesx($texture) - strlen($row['captcha']) * 5)/ 2, 5,  $captcha, $text_color);
    	for($i=0;$i<$length;$i++) {
    		$x = $posx + $i*$font_size*1.3;
    		$y = $posy + rand(-$posy*0.3,$posy*0.3);
    		//if($i>0)	imageline($texture, $x-6, $posy*0.5, $x-6, $posy*1.3, $line_color);
    		imagefttext($texture, $font_size,rand(-30,30), $x, $y, $text_color, $font_file, $captcha[$i]);
    	}
    	
    	//registro il codice
    	$_SESSION['captcha'] = $captcha;
    	
    	//stampo l'immagine
    	header('Content-Type: image/png');
    	imagepng($texture);
    	imagedestroy($texture);
    }
    
    ?>
    
    

    external by Shu Ding modified Mar 18, 2015  90  0  1  0

    Captcha // http://cssdeck.com/labs/captcha

    Captcha // http://cssdeck.com/labs/captcha: captcha.html
    <div style="width:100%; text-align:center" >
      <div>Simple Hard Captcha</div>
      <canvas id="icanvas"></canvas>
      <div width="100%" id="answer">←v←</div>
      <div><a href="http://farter.tk">farter</a></div>
      <div><small>Text positioning broken<br />on firefox?</small></div>
    </div>
    <script>
    
    var MODE=1; /* 1:Demonstration 2:Generate */
    var ZOOM=2;
    var width = icanvas.width = Math.floor(75*ZOOM);
    var height = icanvas.height = Math.floor(14*ZOOM);
    var chrlst = "ABCDEFGHJKLMNPQRSTUVXYZ"//+"23456789"
    
    var Transformer=function()
    {
      var ox,oy,ct,st;
      this.setTrs=function(x,y,t)
      {
        x=x||0; y=y||0; t=t||0;
        ox=x; oy=y; ct=Math.cos(t); st=Math.sin(t);
      }
      this.text=function(ctx,ctxfun,str,x,y)
      {
        ctxfun.call(ctx,str,x*ct-y*st,x*st+y*ct);
      }
      return this;
    }
    var draw = function () {
      
      var cntletter=4,
          anglerange=0.3,
          padding=-0.05,
          paddedwidth=1-padding,
          offxrange=0.05;
      var stylebg="rgba(255,255,255,1)",
          stylefg="rgba(0,0,0,1)";
      
      var ctx=icanvas.getContext('2d');
      ctx.font=(22*ZOOM).toString() + "pt Arial Black";
      ctx.textBaseline="middle";
      ctx.textAlign="center";
      
      var rndpnm=function(r,m)
      {
        return (Math.random()-0.5)*r*m;
      }
      var rndpm=function(r,m)
      {
        return (Math.random())*r*m;
      }
      var trs=new Transformer();
      var capstr="";
      var letters=new Array(cntletter);
      for(var xhl=0;xhl<cntletter;xhl++)
      {
        letters[xhl]={};
        letters[xhl].chr=chrlst[Math.floor(Math.random()*chrlst.length)];
        letters[xhl].x=
          width*padding*0.5 +
          (xhl+0.5)*width*paddedwidth/cntletter +
          rndpnm(offxrange,width);
        letters[xhl].y=height*0.45;
        letters[xhl].angle=rndpnm(anglerange,Math.PI);
        letters[xhl].fill=(Math.random())<0.5?0:1;
        
        if("NWV".indexOf(letters[xhl].chr)!==-1 &&
           xhl>0 &&
           "NWV".indexOf(letters[xhl-1].chr)!==-1
        ) /* paitially avoid ambiguous combinations */
        {
          letters[xhl].chr="A";
        }
        capstr+=letters[xhl].chr;
      }
      ctx.fillStyle=stylebg;
      ctx.fillRect(0,0,width,height);
      ctx.strokeStyle=stylefg;
      ctx.lineWidth=6*ZOOM;
      for(var xhn=0;xhn<5;xhn++)
      {
        ctx.beginPath();
        ctx.moveTo(rndpm(1,width),rndpm(1,height));
        ctx.lineTo(rndpm(1,width),rndpm(1,height));
        ctx.stroke()
      }
      
      ctx.strokeStyle=stylebg;
      for(var xhl=0;xhl<cntletter;xhl++)
      {
        ctx.save();
        trs.setTrs(0,0,-(letters[xhl].angle));
        ctx.rotate(letters[xhl].angle);
        ctx.lineWidth=(letters[xhl].fill?2:3)*ZOOM;
        trs.text(
          ctx,
          ctx.strokeText,
          letters[xhl].chr,letters[xhl].x,letters[xhl].y
        );
        ctx.restore();
      }
      ctx.lineWidth=1*ZOOM;
      ctx.fillStyle=stylefg;
      ctx.strokeStyle=stylefg;
      for(var xhl=0;xhl<cntletter;xhl++)
      {
        ctx.save();
        trs.setTrs(0,0,-(letters[xhl].angle));
        ctx.rotate(letters[xhl].angle);
        trs.text(
          ctx,
          letters[xhl].fill===0?ctx.strokeText:ctx.fillText,
          letters[xhl].chr,letters[xhl].x,letters[xhl].y
        );
        ctx.restore();
      }
      ctx.strokeStyle=stylebg;
      for(var xhl=0;xhl<cntletter;xhl++)
      {
        ctx.lineWidth=(letters[xhl].fill===0?1:2)*ZOOM;
        ctx.beginPath();
        ctx.moveTo(letters[xhl].x+rndpnm(1,width/cntletter),height/2+rndpnm(1,height)/2);
        ctx.lineTo(letters[xhl].x+rndpnm(1,width/cntletter),height/2+rndpnm(1,height)/2);
        ctx.stroke()
      }
      if(MODE===1)
      {
        answer.innerHTML=
          ["←","↖","↑","↗","→","↘","↓","↙"]
            [Math.floor(Math.random()*8)]+
          "v"+
          ["←","↖","↑","↗","→","↘","↓","↙"]
            [Math.floor(Math.random()*8)];
        setTimeout(function(){answer.innerHTML=capstr;},3000);
      }
      return capstr;
    };
    
    if(MODE===1)
    {
      draw();
      setInterval(draw,5000);
    }
    
    if(MODE===2)
    {
      var strall="",capcur="",imgcur="";
      for(var xht=0;xht<45;xht++)
      {
        capcur=draw();
        imgcur=icanvas.toDataURL("image/png");
        strall+=
          "<img src=\"" + imgcur +
          "\"></img>" +
          capcur + " " + Math.round(imgcur.length*(3/4)) + " " +
          ((xht+1)%3==0?"<br>":"");
      }
      document.write(strall);
    }
    </script>
    
    

    external by cyberdecker modified May 6, 2016  71  0  1  0

    Simple test for captcha from tum-vision/captcha-recognition

    Simple test for captcha from tum-vision/captcha-recognition: simpletest.py
    import sys
    
    caffe_root = '/home/user/libs/caffe'
    
    # We need to define how many digits our CAPTCHAs can have at maximum.
    # For simplicity we only have CAPTCHAs of fixed length 6 in this version!
    maxNumberOfDigits = 6
    
    model = 'data_iter_25000.caffemodel'
    
    import numpy as np
    # show whole arrays in outputs
    np.set_printoptions(threshold=np.nan)
    import matplotlib
    # Force matplotlib to not use any Xwindows backend.
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    sys.path.insert(0, caffe_root + 'python')
    import caffe
    import time
    import os
    
    from math import log
    from sklearn import svm, datasets
    from sklearn.cross_validation import train_test_split
    from sklearn.metrics import confusion_matrix
    from random import shuffle
    
    import warnings
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    
    # for copy
    import shutil
    
    
    
    # This function maps the ascii value of a character to a number.
    # 0 -> 0, 1->1, ... 9->9, A->10, B->11, ... Z->35, 
    # a->37, b->38, ... z->62
    # there is a small mistkate! The class 36 is never asigned. But it doesn't matter ;)
    def convertCharacterToClass(ascii_value):
    	if ascii_value > 90:
    		# a small letter
    		correctClass = ascii_value-60
    	elif ascii_value > 57:
    		# a big letter
    		correctClass = ascii_value-55
    	else:
    		# a digit
    		correctClass=ascii_value-48
    	return correctClass
    	
    # This function is the inverse function of convertCharacterToClass
    def convertClassToCharacter(predictedClass):
    	if predictedClass < 10:
    		predictedCharacter = chr(predictedClass+48)
    		#print 'Predicted digit:', predictedCharacter
    	elif predictedClass <= 36:
    		predictedCharacter = chr(predictedClass+55)
    		#print "Predicted big letter", predictedCharacter
    	else:
    		predictedCharacter = chr(predictedClass+60)
    		#print "Predicted small letter", predictedCharacter
    	return predictedCharacter;
    
    network = "network_captchas_with_3_convolutional_layers.prototxt"
    
    # Make classifier.
    classifier = caffe.Classifier(network,model,mean=None)
    
    
    start = time.time()
    
    IMAGE_FILE = 'aaavbz.png'
    #print(IMAGE_FILE)
    
    correctString = os.path.splitext(file)[0]
    #convert the string into a list of chars
    correctChars = list(correctString)
    			
    input_image = caffe.io.load_image(IMAGE_FILE, color=False)
    			
    # convert image to grayscale with 1 channel if it is saved with 3 channels
    # We assume that all three channels are identical and thus just take the second channel and ignore the others
    if input_image.shape[2]>1:
        input_image = input_image[:,:,1]
        input_image = np.reshape(input_image, (50,180,1))
    			
    # print input_image
    inputs = [input_image]
    print input_image.shape
    print inputs
    
    			
    # Classify.
    prediction = classifier.predict(inputs, oversample=False)
    			
    predictedString = ""
    numberOfDigits = 6
    classesPerDigit = 63
    numberOfCorrectChars = 0
    			
    for x in xrange(0, numberOfDigits):
        predictedChar = prediction[0][63*x:63*(x+1)]
        # normalize to a sum of 1
        predictedChar = predictedChar * sum(predictedChar) ** -1
    
        # first guess
        predictedClass = predictedChar.argmax()
        probabilityFirst = predictedChar.max()
        predictedCharacter = convertClassToCharacter(predictedClass)
        predictedString+=predictedCharacter
        
        # secondguess
        predictedChar[predictedClass]=0
        predictedClassSecond = predictedChar.argmax()
        probabilitySecond = predictedChar.max()
        predictedCharacterSecond = convertClassToCharacter(predictedClassSecond)
    
        # unceartainty: 0: absolutley certatin, 1: absoluteley uncertain
        uncertainty = uncertainty + probabilitySecond / probabilityFirst
    
    
    
    
    
    

    external by mour modified Feb 21, 2017  9  0  1  0

    make a captcha, jsut use it to generate data for cracking captcha.

    make a captcha, jsut use it to generate data for cracking captcha.: make_captcha.py
    #!/usr/bin/env python
    # coding: utf-8
    
    import string,random
    import numpy as np
    from captcha.image import ImageCaptcha
    import matplotlib.pyplot as plt
    from PIL import Image
    
    
    
    number = [str(i) for i in range(0,10)]
    
    loweralpha = [ _ for _ in string.lowercase[:26]]
    upperalpha = [ _ for _ in string.uppercase[:26]]
    
    
    def random_captcha_text( source = number+loweralpha+upperalpha, size=4):
    	captcha_text = []
    	for _ in range(size):
    		c = random.choice(source)
    		captcha_text.append(c)
    	return captcha_text
    
    def generate_captch_text_and_image():
    	image = ImageCaptcha()
    
    	captcha_text = random_captcha_text()
    	captcha_text = ''.join(captcha_text)
    
    	captcha = image.generate(captcha_text)
    
    	captcha_image = Image.open(captcha)
    	captcha_image = np.array(captcha_image)		
    	return captcha_text, captcha_image
    	
    
    if __name__ == '__main__':
    	
    	text, image = generate_captch_text_and_image()
    
    	f = plt.figure()
    	ax = f.add_subplot(111)
    	ax.text(0.1,0.9,text,ha='center', va='center', transform=ax.transAxes)
    
    	plt.imshow(image)
    
    	plt.show()
    
    
    

    external by Raszowy modified Dec 21, 2017  5  0  1  0

    captcha pt.2 created by Astehnir - https://repl.it/@Astehnir/captcha-pt2

    captcha pt.2 created by Astehnir - https://repl.it/@Astehnir/captcha-pt2: captcha pt.2.py
    c = input()
    pol = int(len(c)/2)
    print(pol)
    solution = 0
    for i in range(0 , pol):
      if c[i] == c[pol+i]:
         solution = solution + int(c[i])
    print(solution*2)
    
    

    external by Github modified Dec 21, 2017  2  0  1  0

    Captcha pt.2 created by Raszu - https://repl.it/@Raszu/Captcha-pt2

    Captcha pt.2 created by Raszu - https://repl.it/@Raszu/Captcha-pt2: Captcha pt.2.py
    c = input()
    pol = int(len(c)/2)
    
    solution = 0
    for i in range(0 , pol):
      if c[i] == c[pol+i]:
         solution = solution + int(c[i])
    print(solution*2)
    
    
    • Public Snippets
    • Channels Snippets