验证码 captcha

CAPTCHA项目是Completely Automated Public Turing Test to Tell Computers and Humans Apart (全自动区分计算机和人类的图灵测试)的简称,已由卡内基梅隆大学注册商标。
CAPTCHA的目的是区分计算机和人类的一种程序算法,这种程序必须能生成并评价人类能很容易通过但计算机却通不过的测试。这个要求本身就是悖论,因为这意味着一个CAPTCHA必须能生成一个它自己不能通过的测试。
大家可以看看CAPTCHA的一个例子:

人类能够比较容易识别图片中的字母,但如果编写计算机程序,难度就非常大了。
按照Lenore Blum的说法,任何的图片中的内容都能被识别,不存在一种计算程序生成的图片不能被计算机程序识别出来。
于是,比赛开始了,有人站到Captcha一方,有人站到破译Captcha的一方.......

关于Captcha的信息,参考下面的链接
Captcha方:
Captcha项目:http://www.captcha.net/
jCaptcha项目:http://jcaptcha.sourceforge.net/

破译Captcha方:
http://www.cs.sfu.ca/~mori/research/gimpy/
http://sam.zoy.org/pwntcha/
http://www.brains-n-brawn.com/default.aspx?vDir=aicaptcha

在pom.xml文件加入如下内容:

		<dependency>
			<groupId>com.octo.captcha</groupId>
			<artifactId>jcaptcha-all</artifactId>
			<version>1.0-RC6</version>
		</dependency>

 在spring的配置文件里面定义如下:

<!-- set jcaptcha on spring  -->
	<bean id="jcaptchaService"
		class="com.octo.captcha.service.multitype.GenericManageableCaptchaService">
		<constructor-arg index="0">
			<ref bean="imageEngine" />
		</constructor-arg>
		<constructor-arg index="1">
			<value>1</value>
		</constructor-arg>
		<constructor-arg index="2">
			<value>180000</value>
		</constructor-arg>
	</bean>
<!-- coding  way to set imageEngine-->
	<bean id="imageEngine"
		class="com.octo.captcha.engine.image.gimpy.DefaultGimpyEngine">
	</bean>

 官方的Configuration example:

This jcaptcha configuration using spring embeded two configurations files :
The first one configures ImageCaptchaFactories
The second one configures ImageCaptchaEngine and ImageCaptchaService

http://forge.octo.com/jcaptcha/confluence/display/general/ImageCaptchaEngine+components+reference

ImageCaptchaFactories.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>



<!-- ************ FACTORIES declaration  ************-->

		<!-- Constructs a captcha factory which produce captcha,
		 from a word generator (the content) and a word to image (the representation)-->

		<bean id="imageCaptchaFactory" class="com.octo.captcha.image.gimpy.GimpyFactory" >
			<constructor-arg><ref bean="wordgen"/></constructor-arg>
			<constructor-arg><ref bean="wordtoimage"/></constructor-arg>
		</bean>



<!-- ************ WORD 2 IMAGE declaration  ************-->

		<!-- Constructs a WordToImage, which assemble components: a font generator,
			 a background generator, a paster and deformations:
			 the fist one deform the background only (none is the "null" deformation, which does nothing)
			 the second one deform the text only (none is the "null" deformation, which does nothing)
			 the third one deform the hole picture
			 -->
		<bean id="wordtoimage" class="com.octo.captcha.component.image.wordtoimage.ComposedWordToImage" >
			<constructor-arg index="0"><ref bean="fontGenRandom"/></constructor-arg>
			<constructor-arg index="1"><ref bean="backGenUni"/></constructor-arg>
			<constructor-arg index="2"><ref bean="simpleColoredPaster"/></constructor-arg>
<!--			<constructor-arg index="3"><ref bean="none"/></constructor-arg>-->
<!--			<constructor-arg index="4"><ref bean="none"/></constructor-arg>-->
<!--			<constructor-arg index="5"><ref bean="ripple3Def"/></constructor-arg>-->
		</bean>

 <!-- ************ BACKGROUND declaration  ************-->

		<!-- Constructs a background generator,
			this one is the default Unicolor, white is background color -->
		<bean id="backGenUni" class="com.octo.captcha.component.image.backgroundgenerator.UniColorBackgroundGenerator" >
						<constructor-arg index="0"><value>300</value></constructor-arg>
						<constructor-arg index="1"><value>100</value></constructor-arg>
		</bean>

<!-- ************ FONT  declaration  ************-->

		<bean id="fontArial" class="java.awt.Font" >
			<constructor-arg index="0"><value>Arial</value></constructor-arg>
			<constructor-arg index="1"><value>0</value></constructor-arg>
			<constructor-arg index="2"><value>10</value></constructor-arg>
		</bean>

		<bean id="fontTahoma" class="java.awt.Font" >
			<constructor-arg index="0"><value>Tahoma</value></constructor-arg>
			<constructor-arg index="1"><value>0</value></constructor-arg>
			<constructor-arg index="2"><value>10</value></constructor-arg>
		</bean>

		<bean id="fontVerdana" class="java.awt.Font" >
			<constructor-arg index="0"><value>Verdana</value></constructor-arg>
			<constructor-arg index="1"><value>0</value></constructor-arg>
			<constructor-arg index="2"><value>10</value></constructor-arg>
		</bean>

		<bean id="fontComic" class="java.awt.Font" >
			<constructor-arg index="0"><value>Comic sans MS</value></constructor-arg>
			<constructor-arg index="1"><value>0</value></constructor-arg>
			<constructor-arg index="2"><value>10</value></constructor-arg>
		</bean>

		<bean id="fontLucida" class="java.awt.Font" >
			<constructor-arg index="0"><value>Lucida console</value></constructor-arg>
			<constructor-arg index="1"><value>0</value></constructor-arg>
			<constructor-arg index="2"><value>10</value></constructor-arg>
		</bean>
<!-- ************ FONT GENERATOR declaration  ************-->

		<!-- Constructs Font generator, with the min and max size of font,
			and with a list of fonts-->
		<bean id="fontGenRandom" class="com.octo.captcha.component.image.fontgenerator.RandomFontGenerator" >
						<constructor-arg index="0"><value>40</value></constructor-arg>
 						<constructor-arg index="1"><value>50</value></constructor-arg>
						<constructor-arg index="2">
								<list>
									<ref bean="fontArial"/>
									<ref bean="fontTahoma"/>
									<ref bean="fontVerdana"/>
									<ref bean="fontComic"/>
									<ref bean="fontLucida"/>
								</list>
						</constructor-arg>
		</bean>

<!-- ************ PASTER declaration  ************-->

		<!-- Constructs the paster component, a baffle one, which make holes in characters
			Parameters :
			int for the min length of the word
			int for the max length of the word
			ColorGenerator for the color of the word
			boolean to know if each character can have a different color
			-->
		<bean id="simpleColoredPaster" class="com.octo.captcha.component.image.textpaster.RandomTextPaster" >
						<constructor-arg type="java.lang.Integer" index="0"><value>4</value></constructor-arg>
						<constructor-arg type="java.lang.Integer" index="1"><value>6</value></constructor-arg>
						<constructor-arg type="com.octo.captcha.component.image.color.ColorGenerator" index="2"><ref bean="colorGenRandomDark"/></constructor-arg>
						<constructor-arg index="3"><value>true</value></constructor-arg>
		</bean>


<!-- ************ DIC and WORD GENERATOR declaration  ************-->

		<!-- Constructs a File diconnary, which will read words from a file, corresponding to Locle (for instance with locale France,
			 it will look for the file : toddlist_fr_FR.properties, if not found, take toddlist.properties -->
		<bean id="filedict" class="com.octo.captcha.component.wordgenerator.FileDictionnary" >
			<constructor-arg index="0"><value>toddlist</value></constructor-arg>
		</bean>

	<!--	<bean id="wordgen" class="com.octo.captcha.component.wordgenerator.DictionaryWordGenerator" >
			<constructor-arg><ref bean="filedict"/></constructor-arg>
		</bean>-->

		<!-- Constructs a word generator, which composed words from existing words
			It takes a diconnary for the existing words-->
		<bean id="wordgen" class="com.octo.captcha.component.wordgenerator.ComposeDictionaryWordGenerator" >
			<constructor-arg><ref bean="filedict"/></constructor-arg>
		</bean>

<!-- ************ FILTER  declaration  ************-->

		<!-- Constructs the "null" deformation component-->
		<bean id="none" class="com.octo.captcha.component.image.deformation.ImageDeformationByFilters" >
			<constructor-arg index="0">
				<null/>
            </constructor-arg>
		</bean>

<!-- ************ COLORS Declarations ************-->

		<!-- Constructs a java Color-->
		<bean id="white" class="java.awt.Color" >
			<constructor-arg type="int" index="0"><value>255</value></constructor-arg>
			<constructor-arg type="int" index="1"><value>255</value></constructor-arg>
			<constructor-arg type="int" index="2"><value>255</value></constructor-arg>
		</bean>

		<!-- Constructs a color generator which generate one color -->
		<bean id="colorGenWhite" class="com.octo.captcha.component.image.color.SingleColorGenerator" >
			<constructor-arg index="0"><ref bean="white"/></constructor-arg>
		</bean>

		<!-- Constructs a color generator which generate dark color correspond to the different ranges-->
		<bean id="colorGenRandomDark" class="com.octo.captcha.component.image.color.RandomRangeColorGenerator" >
			<constructor-arg index="0">
				<list>
	                <value>0</value>
	                <value>150</value>
            	</list>
            </constructor-arg>
			<constructor-arg index="1">
				<list>
	                <value>0</value>
	                <value>150</value>
            	</list>
            </constructor-arg>
			<constructor-arg index="2">
				<list>
	                <value>0</value>
	                <value>150</value>
            	</list>
            </constructor-arg>
			<constructor-arg index="3">
				<list>
	                <value>255</value>
	                <value>255</value>
            	</list>
            </constructor-arg>
		</bean>




</beans>

 

ImageCaptchaService.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>


<!-- Constructs a captcha engine, with custom factories-->
	<bean
		class="com.octo.captcha.engine.GenericCaptchaEngine" id="imageEngine">
		<constructor-arg index="0">
				<list>
					<ref bean="imageCaptchaFactory"/>
				</list>
		</constructor-arg>
	</bean>

	<bean id="imageCaptchaService"
		class="com.octo.captcha.service.multitype.GenericManageableCaptchaService">
		<constructor-arg index="0">
			<ref bean="imageEngine"/>
		</constructor-arg>
        <constructor-arg index="1"><value>300</value></constructor-arg>
        <constructor-arg index="2"><value>200000</value></constructor-arg>
	</bean>
</beans>

 

你可能感兴趣的:(spring,bean,xml,算法,.net)