Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Captcha for Flash CS3

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Captcha for Flash CS3

    flash templates

    FlepStudio has created a simple captcha for Flash CS3 with Actionscript 3.0.


    What a CAPTCHA is ?

    A CAPTCHA is a type of challenge-response test used in computing to determine that the response is not generated by a computer. The process involves one computer (a server) asking a user to complete a simple test which the computer is able to generate and grade.

    Because other computers are unable to solve the CAPTCHA, any user entering a correct solution is presumed to be human. A common type of CAPTCHA requires that the user type the letters of a distorted image, sometimes with the addition of an obscured sequence of letters or digits that appears on the screen.


    FlepStudio has created a Flash captcha that can be used in your guestbook or shoutbox.

    It can be used in any application that requires the Flash insertion of comments or messages from users.


    It 'a simple class Actionscript 3.0 easily manageable through its checkCaptcha method.


    Flash CS3 CAPTCHA






    Actionscript 3.0 Captcha.as class


    Code:
    package org.FlepStudio
    {
    	import flash.display.*;
    	import flash.events.*;
    	import flash.geom.*;
    	import flash.text.*;
    	
    	public class Captcha extends MovieClip
    	{
    		private var clip_mc:MovieClip;
    		
    		private var captcha_array:Array;
    		
    		private const CAPTCHA_LENGTH:int=8;
    		
    		private var captcha:String="";
    		
    		public function Captcha()
    		{
    			addEventListener(Event.ADDED_TO_STAGE,init);
    		}
    		
    		private function init(evt:Event):void
    		{
    			removeEventListener(Event.ADDED_TO_STAGE,init);
    			
    			captcha_array=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j",
    							    					"k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
    			
    			createClip();
    			createBackground();
    			createCaptcha();
    			createText();
    		}
    		
    		private function createClip():void
    		{
    			clip_mc=new MovieClip();
    			addChild(clip_mc);
    		}
    		
    		private function createBackground():void
    		{
    			var fillType:String=GradientType.LINEAR;
    			var colors:Array=[Math.random()*0xFFFFFF,Math.random()*0xFFFFFF];
    			var alphas:Array=[1,1];
    			var ratios:Array=[0x00,0xFF];
    			var matr:Matrix=new Matrix();
    			matr.createGradientBox(20,20,0,0,0);
    			var spreadMethod:String=SpreadMethod.REFLECT;
    			clip_mc.graphics.beginGradientFill(fillType,colors,alphas,ratios,matr,spreadMethod);  
    			clip_mc.graphics.drawRect(0,0,140,40);
    		}
    		
    		private function createCaptcha():void
    		{
    			for(var i:int=0;i < CAPTCHA_LENGTH;i++)
    			{
    				var randomNumber:int=Math.floor(Math.random()*captcha_array.length);
    				captcha+=captcha_array[randomNumber];
    			}
    		}
    		
    		private function createText():void
    		{
    			var field_txt:TextField=new TextField();
    			field_txt.multiline=false;
    			field_txt.selectable=false;
    			field_txt.embedFonts=true;
    			field_txt.defaultTextFormat=getFormat();
    			field_txt.text=captcha;
    			field_txt.width=field_txt.textWidth+5;
    			field_txt.height=field_txt.textHeight;
    			field_txt.x=(clip_mc.width-field_txt.textWidth)/2;
    			field_txt.y=(clip_mc.height-field_txt.textHeight)/2;
    			clip_mc.addChild(field_txt);
    		}
    		
    		private function getFormat():TextFormat
    		{
    			var format:TextFormat=new TextFormat();
    			format.font="Flubber";
    			format.size=24;
    			format.color=0xFFFFFF;
    			
    			return format;
    		}
    		
    		public function checkCaptcha(str:String):Boolean
    		{
    			if(str===captcha)
    				return true;
    			else
    				return false;
    		}
    	}
    }

    How to use Catcha.as class


    Code:
    import org.FlepStudio.Captcha;
    
    var test:Captcha=new Captcha();
    test.x=260;
    test.y=160;
    addChild(test);
    
    send_btn.addEventListener(MouseEvent.MOUSE_DOWN,setDown);
    
    function setDown(evt:MouseEvent):void
    {
    	var answer:Boolean=test.checkCaptcha(test_txt.text);
    	trace(answer);
    }

    Methods


    checkCaptcha(String):Boolean


    Once instantiated the class and attached to the stage ( or into another MovieClip ), just call this method passing the string of user who is inserting in the text field.
    You will receive a Boolean return value (true or false) and based on that value decide the actions to do for your application.

    Attached Files

  2. #2
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: Captcha for Flash CS3

    PS:

    is someone thinks it's too hard to catch the letters, just change the font

  3. #3
    Junior Member Settled In flashkiddy is on a distinguished road
    Join Date
    Mar 2008
    Posts
    3
    Rep Power
    0

    Re: Captcha for Flash CS3

    nice and clean code dude. But isnt the whole idea about this technology that you keep the code on the server instead of on the client side? Now someone can still write an exploitation script to misuse the fact that the captcha-code is accessible directly from the browser.

  4. #4
    Junior Member Settled In Oldarney is on a distinguished road
    Join Date
    Feb 2008
    Posts
    5
    Rep Power
    0

    Re: Captcha for Flash CS3

    makes since. captcha's are for security and this isnt very. a small modification to the original web page that this is implanted (greasemonkey or firebug) and this would be useless.

    now if, it loaded the image from a server then sent back the user input...

  5. #5
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: Captcha for Flash CS3

    Hi,
    do not confuse a server Captcha with a Flash Captcha.
    You are inside of a SWF, bots can't get into a SWF.
    This captcha is usefull if you have for example a guestbook and you do not want permit the user to write comments fast with no reason.
    Or you can use it with a flash email form.

    Flash does not need a real server captcha because bots can't work inside SWF.

  6. #6
    Junior Member Settled In Oldarney is on a distinguished road
    Join Date
    Feb 2008
    Posts
    5
    Rep Power
    0

    Re: Captcha for Flash CS3

    nope, but cheat engine can. its a nice alternative for the mention reasons though. that is if you don't need the utmost security.

  7. #7
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: Captcha for Flash CS3

    Quote Originally Posted by Oldarney View Post
    that is if you don't need the utmost security.
    yep
    agree

  8. #8
    Junior Member Settled In edanlee is on a distinguished road
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Re: Captcha for Flash CS3

    is it case sensitive?

  9. #9
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    Re: Captcha for Flash CS3

    Yes it is

  10. #10
    Junior Member Settled In Petepool is on a distinguished road
    Join Date
    Jan 2008
    Posts
    1
    Rep Power
    0

    Question Re: Captcha for Flash CS3

    Quote Originally Posted by Flep View Post
    PS:

    is someone thinks it's too hard to catch the letters, just change the font
    Hi,
    I am trying to change the font and must be missing something. I did this change in the Captcha.as file:

    private function getFormat():TextFormat
    {
    var format:TextFormat=new TextFormat();
    format.font="Courier New";
    //format.font="Flubber";
    format.size=24;
    format.color=0xFFFFFF;

    return format;
    }

    But when I run the flash, I just get the background and the text in the captcha graphic is not visable.

    Thanks for any help.

    PS This site is fantastic! What a great find for a newbee!

+ Reply to Thread
Page 1 of 2 1 2 LastLast

LinkBacks (?)

  1. 06-01-09, 02:53
  2. 28-12-08, 23:45
  3. 17-12-08, 01:12
  4. 24-05-08, 04:49
  5. 21-05-08, 13:30
  6. 21-05-08, 13:13
  7. 21-05-08, 09:22
  8. 21-05-08, 08:47

Similar Threads

  1. Captcha per Flash CS3
    By Flep in forum Utilità di FlepStudio
    Replies: 19
    Last Post: 05-11-09, 05:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts