<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Venkatasai's Blog : CAPTCHA</title><link>http://weblogs.asp.net/karlapudi/archive/tags/CAPTCHA/default.aspx</link><description>Tags: CAPTCHA</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Custom CAPTCHA Image Action Result for ASP.NET MVC</title><link>http://weblogs.asp.net/karlapudi/archive/2008/05/13/custom-captcha-image-action-result-for-asp-net-mvc.aspx</link><pubDate>Wed, 14 May 2008 02:23:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6188015</guid><dc:creator>Karlapudi</dc:creator><slash:comments>0</slash:comments><comments>http://weblogs.asp.net/karlapudi/archive/2008/05/13/custom-captcha-image-action-result-for-asp-net-mvc.aspx#comments</comments><description>&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Times New Roman" size=3&gt;In this post you will see how to create &lt;/FONT&gt;&lt;A href="http://en.wikipedia.org/wiki/Captcha" mce_href="http://en.wikipedia.org/wiki/Captcha"&gt;&lt;FONT face="Times New Roman" color=#800080 size=3&gt;CAPTCHA&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face="Times New Roman" size=3&gt; style image using ActionResult object introduced in &lt;/FONT&gt;&lt;A href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=12640" mce_href="http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=12640"&gt;&lt;FONT face="Times New Roman" color=#800080 size=3&gt;April ASP.Net source refresh at code plex&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Create CAPTCHAImageActionResult to render generated image with random text &lt;BR&gt;&lt;/U&gt;&lt;/STRONG&gt;Here is the code of custom action result class which do all the work to generate image .Nice thing about this is&amp;nbsp; back ground color, font color and random text are properties and can be set by controller&amp;nbsp; based color scheme of your web site.&lt;/P&gt;
&lt;P&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/karlapudi/ActionResult1.gif" target=_blank mce_href="http://weblogs.asp.net/blogs/karlapudi/ActionResult1.gif"&gt;&lt;IMG style="WIDTH: 735px; HEIGHT: 481px" height=481 src="http://weblogs.asp.net/blogs/karlapudi/ActionResult1.gif" width=735 align=bottom mce_src="http://weblogs.asp.net/blogs/karlapudi/ActionResult1.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/karlapudi/ActionResult2.gif" target=_blank mce_href="http://weblogs.asp.net/blogs/karlapudi/ActionResult2.gif"&gt;&lt;IMG style="WIDTH: 735px; HEIGHT: 481px" height=481 src="http://weblogs.asp.net/blogs/karlapudi/ActionResult2.gif" width=735 align=bottom mce_src="http://weblogs.asp.net/blogs/karlapudi/ActionResult2.gif"&gt;&lt;/A&gt;&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Create Controller action to process request for CAPTCHA image.&lt;/U&gt;&lt;/STRONG&gt; &lt;BR&gt;Create ASP.Net MVC controller class to generate random text and then to return custom CAPTCHAImageActionResult object. Here is the code how it looks like. In this example I am generating simple random text with some numbers and alphabets&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;A class="" href="http://weblogs.asp.net/blogs/karlapudi/Controller.gif" target=_blank mce_href="http://weblogs.asp.net/blogs/karlapudi/Controller.gif"&gt;&lt;IMG style="WIDTH: 735px; HEIGHT: 577px" height=577 src="http://weblogs.asp.net/blogs/karlapudi/Controller.gif" width=735 align=bottom mce_src="http://weblogs.asp.net/blogs/karlapudi/Controller.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Use in view pages&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Now it is time to use this in other view pages, add below line in any of view page. In this example I have used in homepage. &lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;EM&gt;&amp;lt;img alt="CAPTCHA Image" src="&amp;lt;%=Url.Action("Index","CAPTCHAImage") %&amp;gt;"/&amp;gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Here is how the screen looks like.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;IMG style="WIDTH: 768px; HEIGHT: 399px" height=399 src="http://weblogs.asp.net/blogs/karlapudi/HomeScreen.JPG" width=768 align=bottom mce_src="http://weblogs.asp.net/blogs/karlapudi/HomeScreen.JPG "&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can download sample code &lt;A class="" href="http://weblogs.asp.net/blogs/karlapudi/CAPTCHAImage.zip" mce_href="http://weblogs.asp.net/blogs/karlapudi/CAPTCHAImage.zip"&gt;here&lt;/A&gt; &lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6188015" width="1" height="1"&gt;</description><category domain="http://weblogs.asp.net/karlapudi/archive/tags/MVC/default.aspx">MVC</category><category domain="http://weblogs.asp.net/karlapudi/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://weblogs.asp.net/karlapudi/archive/tags/.Net/default.aspx">.Net</category><category domain="http://weblogs.asp.net/karlapudi/archive/tags/Action+Result/default.aspx">Action Result</category><category domain="http://weblogs.asp.net/karlapudi/archive/tags/CAPTCHA/default.aspx">CAPTCHA</category></item></channel></rss>