<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: How To Create a CAPTCHA Graphic in VB.NET</title>
	<atom:link href="http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/</link>
	<description>Articles on VB.NET and Software Development Team Leadership</description>
	<pubDate>Tue, 22 May 2012 11:57:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Vasanth</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1449</link>
		<dc:creator>Vasanth</dc:creator>
		<pubDate>Fri, 29 Jan 2010 16:25:51 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1449</guid>
		<description>hi venkat ,

we can also use characters or numbers or mixed characters otrnumbers by modifying the code with the single function which is shown below

Imports System.Web.SessionState
Imports System.Drawing
Imports System.Drawing.Imaging

Public Class Captcha

    Protected RandomValue As New Random

    Protected _captchaImage As Bitmap
    Protected _captchaHeight As Integer
    Protected _captchaWidth As Integer
    Protected _captchaFont As Font
    Protected _captchaCode As String

    ''' 
    ''' Useful for subclassing
    ''' 
    ''' 
    Public Sub New()

    End Sub

    ''' 
    ''' Loads properties and generates an initial captcha value and graphic
    ''' 
    ''' The Width of the Captcha Graphic
    ''' The Height of the Captcha Graphic
    ''' The Font of the Captcha Graphic
    ''' 
    Public Sub New(ByVal imageWidth As Integer, ByVal imageHeight As Integer, ByVal imageFont As Font)
        _captchaHeight = imageHeight
        _captchaWidth = imageWidth
        _captchaFont = imageFont
        GenerateNewCaptcha()
    End Sub

    ''' 
    ''' Generates a new captcha value and graphic for the class
    ''' 
    ''' 
    Public Sub GenerateNewCaptcha()
        If _captchaFont Is Nothing OrElse _captchaHeight = 0 OrElse _captchaWidth = 0 Then
            Exit Sub
        End If
        _captchaCode = getrandomstring()
        _captchaImage = New Bitmap(_captchaWidth, _captchaHeight)
        Using CaptchaGraphics As Graphics = Graphics.FromImage(CaptchaImage)
            Using BackgroundBrush As New Drawing2D.HatchBrush(Drawing2D.HatchStyle.SmallGrid, Color.GhostWhite, Color.WhiteSmoke)
                CaptchaGraphics.FillRectangle(BackgroundBrush, 0, 0, _captchaWidth, _captchaHeight)
            End Using
            Dim CharacterSpacing As Integer = (_captchaWidth \ 5) - 1
            Dim HorizontalPosition As Integer
            Dim MaxVerticalPosition As Integer
            For Each CharValue As Char In _captchaCode.ToCharArray
                MaxVerticalPosition = _captchaHeight - Convert.ToInt32(CaptchaGraphics.MeasureString(CharValue, _captchaFont).Height)
                CaptchaGraphics.DrawString(CharValue, _captchaFont, Brushes.DimGray, HorizontalPosition, RandomValue.Next(0, MaxVerticalPosition))
                HorizontalPosition += CharacterSpacing + RandomValue.Next(-1, 1)
            Next
            For Counter As Integer = 0 To 24
                CaptchaGraphics.FillEllipse(Brushes.DimGray, RandomValue.Next(1, _captchaWidth), RandomValue.Next(1, _captchaHeight), RandomValue.Next(1, 4), RandomValue.Next(1, 4))
            Next
            For Counter As Integer = 0 To 24
                CaptchaGraphics.FillEllipse(Brushes.WhiteSmoke, RandomValue.Next(1, _captchaWidth), RandomValue.Next(1, _captchaHeight), RandomValue.Next(1, 4), RandomValue.Next(1, 4))
            Next
        End Using
    End Sub

    ''' 
    ''' The captcha bitmap image
    ''' 
    ''' 
    ''' 
    ''' 
    Private Function getrandomstring() As String
        Dim arrstr() As String
        arrstr = "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,1,2,3,4,5,6,7,8,9,0".Split(",".ToCharArray())
        Dim strdraw As String
        Dim r As Random
        r = New Random()
        strdraw = String.Empty
        Dim i As Integer
        For i = 0 To 4
            strdraw += arrstr(r.Next(0, arrstr.Length - 1))
        Next
        Return strdraw
    End Function
    Public Property CaptchaImage() As Bitmap
        Get
            Return _captchaImage
        End Get
        Set(ByVal value As Bitmap)
            _captchaImage = value
        End Set
    End Property

    ''' 
    ''' The value of the captcha
    ''' 
    ''' 
    ''' 
    ''' 
    Public Property CaptchaCode() As String
        Get
            Return _captchaCode
        End Get
        Set(ByVal value As String)
            _captchaCode = value
        End Set
    End Property

    ''' 
    ''' The Height of the Captcha Graphic
    ''' 
    ''' 
    ''' 
    ''' 
    Public Property CaptchaHeight() As Integer
        Get
            Return _captchaHeight
        End Get
        Set(ByVal value As Integer)
            _captchaHeight = value
        End Set
    End Property

    ''' 
    ''' The Width of the Captcha Graphic
    ''' 
    ''' 
    ''' 
    ''' 
    Public Property CaptchaWidth() As Integer
        Get
            Return _captchaWidth
        End Get
        Set(ByVal value As Integer)
            _captchaWidth = value
        End Set
    End Property

    ''' 
    ''' The Font of the Captcha Graphic
    ''' 
    ''' 
    ''' 
    ''' 
    Public Property CaptchaFont() As Font
        Get
            Return _captchaFont
        End Get
        Set(ByVal value As Font)
            _captchaFont = value
        End Set
    End Property

End Class</description>
		<content:encoded><![CDATA[<p>hi venkat ,</p>
<p>we can also use characters or numbers or mixed characters otrnumbers by modifying the code with the single function which is shown below</p>
<p>Imports System.Web.SessionState<br />
Imports System.Drawing<br />
Imports System.Drawing.Imaging</p>
<p>Public Class Captcha</p>
<p>    Protected RandomValue As New Random</p>
<p>    Protected _captchaImage As Bitmap<br />
    Protected _captchaHeight As Integer<br />
    Protected _captchaWidth As Integer<br />
    Protected _captchaFont As Font<br />
    Protected _captchaCode As String</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; Useful for subclassing<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Sub New()</p>
<p>    End Sub</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; Loads properties and generates an initial captcha value and graphic<br />
    &#8221;&#8217;<br />
    &#8221;&#8217; The Width of the Captcha Graphic<br />
    &#8221;&#8217; The Height of the Captcha Graphic<br />
    &#8221;&#8217; The Font of the Captcha Graphic<br />
    &#8221;&#8217;<br />
    Public Sub New(ByVal imageWidth As Integer, ByVal imageHeight As Integer, ByVal imageFont As Font)<br />
        _captchaHeight = imageHeight<br />
        _captchaWidth = imageWidth<br />
        _captchaFont = imageFont<br />
        GenerateNewCaptcha()<br />
    End Sub</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; Generates a new captcha value and graphic for the class<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Sub GenerateNewCaptcha()<br />
        If _captchaFont Is Nothing OrElse _captchaHeight = 0 OrElse _captchaWidth = 0 Then<br />
            Exit Sub<br />
        End If<br />
        _captchaCode = getrandomstring()<br />
        _captchaImage = New Bitmap(_captchaWidth, _captchaHeight)<br />
        Using CaptchaGraphics As Graphics = Graphics.FromImage(CaptchaImage)<br />
            Using BackgroundBrush As New Drawing2D.HatchBrush(Drawing2D.HatchStyle.SmallGrid, Color.GhostWhite, Color.WhiteSmoke)<br />
                CaptchaGraphics.FillRectangle(BackgroundBrush, 0, 0, _captchaWidth, _captchaHeight)<br />
            End Using<br />
            Dim CharacterSpacing As Integer = (_captchaWidth \ 5) - 1<br />
            Dim HorizontalPosition As Integer<br />
            Dim MaxVerticalPosition As Integer<br />
            For Each CharValue As Char In _captchaCode.ToCharArray<br />
                MaxVerticalPosition = _captchaHeight - Convert.ToInt32(CaptchaGraphics.MeasureString(CharValue, _captchaFont).Height)<br />
                CaptchaGraphics.DrawString(CharValue, _captchaFont, Brushes.DimGray, HorizontalPosition, RandomValue.Next(0, MaxVerticalPosition))<br />
                HorizontalPosition += CharacterSpacing + RandomValue.Next(-1, 1)<br />
            Next<br />
            For Counter As Integer = 0 To 24<br />
                CaptchaGraphics.FillEllipse(Brushes.DimGray, RandomValue.Next(1, _captchaWidth), RandomValue.Next(1, _captchaHeight), RandomValue.Next(1, 4), RandomValue.Next(1, 4))<br />
            Next<br />
            For Counter As Integer = 0 To 24<br />
                CaptchaGraphics.FillEllipse(Brushes.WhiteSmoke, RandomValue.Next(1, _captchaWidth), RandomValue.Next(1, _captchaHeight), RandomValue.Next(1, 4), RandomValue.Next(1, 4))<br />
            Next<br />
        End Using<br />
    End Sub</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; The captcha bitmap image<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Private Function getrandomstring() As String<br />
        Dim arrstr() As String<br />
        arrstr = &#8220;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,1,2,3,4,5,6,7,8,9,0&#8243;.Split(&#8221;,&#8221;.ToCharArray())<br />
        Dim strdraw As String<br />
        Dim r As Random<br />
        r = New Random()<br />
        strdraw = String.Empty<br />
        Dim i As Integer<br />
        For i = 0 To 4<br />
            strdraw += arrstr(r.Next(0, arrstr.Length - 1))<br />
        Next<br />
        Return strdraw<br />
    End Function<br />
    Public Property CaptchaImage() As Bitmap<br />
        Get<br />
            Return _captchaImage<br />
        End Get<br />
        Set(ByVal value As Bitmap)<br />
            _captchaImage = value<br />
        End Set<br />
    End Property</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; The value of the captcha<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Property CaptchaCode() As String<br />
        Get<br />
            Return _captchaCode<br />
        End Get<br />
        Set(ByVal value As String)<br />
            _captchaCode = value<br />
        End Set<br />
    End Property</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; The Height of the Captcha Graphic<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Property CaptchaHeight() As Integer<br />
        Get<br />
            Return _captchaHeight<br />
        End Get<br />
        Set(ByVal value As Integer)<br />
            _captchaHeight = value<br />
        End Set<br />
    End Property</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; The Width of the Captcha Graphic<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Property CaptchaWidth() As Integer<br />
        Get<br />
            Return _captchaWidth<br />
        End Get<br />
        Set(ByVal value As Integer)<br />
            _captchaWidth = value<br />
        End Set<br />
    End Property</p>
<p>    &#8221;&#8217;<br />
    &#8221;&#8217; The Font of the Captcha Graphic<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    &#8221;&#8217;<br />
    Public Property CaptchaFont() As Font<br />
        Get<br />
            Return _captchaFont<br />
        End Get<br />
        Set(ByVal value As Font)<br />
            _captchaFont = value<br />
        End Set<br />
    End Property</p>
<p>End Class</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Webdevelopment company</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1398</link>
		<dc:creator>Webdevelopment company</dc:creator>
		<pubDate>Sat, 19 Sep 2009 06:42:51 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1398</guid>
		<description>As i am fresher in vb.net development  thanks a lot to give me insight in captcha it helps me a  lot.</description>
		<content:encoded><![CDATA[<p>As i am fresher in vb.net development  thanks a lot to give me insight in captcha it helps me a  lot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkat</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1330</link>
		<dc:creator>venkat</dc:creator>
		<pubDate>Tue, 31 Mar 2009 06:21:43 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1330</guid>
		<description>hai..

As you said you have to store the image in your project folder..

If it happen like this.. if the number of user visiting that page in the 

sense - so there are no.of images stored in the My Images folder

how to avoid this....

how to use Character Instead of numbers... to display in the image..</description>
		<content:encoded><![CDATA[<p>hai..</p>
<p>As you said you have to store the image in your project folder..</p>
<p>If it happen like this.. if the number of user visiting that page in the </p>
<p>sense - so there are no.of images stored in the My Images folder</p>
<p>how to avoid this&#8230;.</p>
<p>how to use Character Instead of numbers&#8230; to display in the image..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toner</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1274</link>
		<dc:creator>Toner</dc:creator>
		<pubDate>Tue, 23 Dec 2008 22:30:07 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1274</guid>
		<description>To integrate:           

 Dim myCaptcha As New Captcha
            myCaptcha.CaptchaHeight = 50
            myCaptcha.CaptchaWidth = 150
            myCaptcha.CaptchaFont = New Font("Verdana", 20, FontStyle.Regular)
            myCaptcha.GenerateNewCaptcha()

            myCaptcha.CaptchaImage.Save(Request.PhysicalApplicationPath &amp; "images\captcha\" &amp; myCaptcha.CaptchaCode &amp; ".jpg")
            ltrCaptcha.Text = myCaptcha.CaptchaCode

            imgCaptcha.ImageUrl = "../images/captcha/" &amp; myCaptcha.CaptchaCode &amp; ".jpg"


Then on user input just check wheter invisble ltrCaptcha text is same as user's input!</description>
		<content:encoded><![CDATA[<p>To integrate:           </p>
<p> Dim myCaptcha As New Captcha<br />
            myCaptcha.CaptchaHeight = 50<br />
            myCaptcha.CaptchaWidth = 150<br />
            myCaptcha.CaptchaFont = New Font(&#8221;Verdana&#8221;, 20, FontStyle.Regular)<br />
            myCaptcha.GenerateNewCaptcha()</p>
<p>            myCaptcha.CaptchaImage.Save(Request.PhysicalApplicationPath &amp; &#8220;images\captcha\&#8221; &amp; myCaptcha.CaptchaCode &amp; &#8220;.jpg&#8221;)<br />
            ltrCaptcha.Text = myCaptcha.CaptchaCode</p>
<p>            imgCaptcha.ImageUrl = &#8220;../images/captcha/&#8221; &amp; myCaptcha.CaptchaCode &amp; &#8220;.jpg&#8221;</p>
<p>Then on user input just check wheter invisble ltrCaptcha text is same as user&#8217;s input!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cathy</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1166</link>
		<dc:creator>Cathy</dc:creator>
		<pubDate>Mon, 21 Jul 2008 06:07:25 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1166</guid>
		<description>Hi,

I would like to know the design part of the code.. i.e.captcha</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I would like to know the design part of the code.. i.e.captcha</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jfrankcarr</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1093</link>
		<dc:creator>jfrankcarr</dc:creator>
		<pubDate>Wed, 23 Apr 2008 18:50:26 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1093</guid>
		<description>Hi Chuck,

That is true. However, there are some blackhat scripts around that I've seen that will do some equation solving for captchas, particularly if it's worded like you have in your comment. 

It's a never ending battle against spam. While I don't update this site often due to other commitments, I do keep an eye on it. In the past 3 months there have been over 10000 spam comment attempts. Akismet, while not perfect, does a good job of keeping them at bay.</description>
		<content:encoded><![CDATA[<p>Hi Chuck,</p>
<p>That is true. However, there are some blackhat scripts around that I&#8217;ve seen that will do some equation solving for captchas, particularly if it&#8217;s worded like you have in your comment. </p>
<p>It&#8217;s a never ending battle against spam. While I don&#8217;t update this site often due to other commitments, I do keep an eye on it. In the past 3 months there have been over 10000 spam comment attempts. Akismet, while not perfect, does a good job of keeping them at bay.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1092</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Wed, 23 Apr 2008 17:46:39 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1092</guid>
		<description>Sometime even more effective than captcha is just asking a simple, easy for humans to understand, hard for computers to grasp, question.

Something as simple as "What is the sum of 10 and 5?"

As far as I know, there are no bots out there yet smart enough to decipher such simple questions. A more sophisticated system could randomize a set of simple questions, to make it even more secure.

What color is the sun? Yellow.
What is the name of the planet on which we live? Earth

and so on.

Another advantage is this is more accessible to the vision-impaired.</description>
		<content:encoded><![CDATA[<p>Sometime even more effective than captcha is just asking a simple, easy for humans to understand, hard for computers to grasp, question.</p>
<p>Something as simple as &#8220;What is the sum of 10 and 5?&#8221;</p>
<p>As far as I know, there are no bots out there yet smart enough to decipher such simple questions. A more sophisticated system could randomize a set of simple questions, to make it even more secure.</p>
<p>What color is the sun? Yellow.<br />
What is the name of the planet on which we live? Earth</p>
<p>and so on.</p>
<p>Another advantage is this is more accessible to the vision-impaired.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sanjai Malani</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1059</link>
		<dc:creator>Sanjai Malani</dc:creator>
		<pubDate>Tue, 08 Apr 2008 06:37:57 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1059</guid>
		<description>How do you call this class and use it in the page?</description>
		<content:encoded><![CDATA[<p>How do you call this class and use it in the page?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yoko</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1017</link>
		<dc:creator>Yoko</dc:creator>
		<pubDate>Sun, 09 Mar 2008 03:39:42 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1017</guid>
		<description>Very informative. Thanks for sharing. :)</description>
		<content:encoded><![CDATA[<p>Very informative. Thanks for sharing. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/comment-page-1/#comment-1012</link>
		<dc:creator>David</dc:creator>
		<pubDate>Wed, 27 Feb 2008 00:04:37 +0000</pubDate>
		<guid isPermaLink="false">http://vbnotebookfor.net/2007/11/06/how-to-create-a-captcha-graphic-in-vbnet/#comment-1012</guid>
		<description>How do you call this class and use it in the page?</description>
		<content:encoded><![CDATA[<p>How do you call this class and use it in the page?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

