Create you own Captcha Code in ASP.Net

Captcha.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim imgSrc As New Bitmap(100, 30)
        Dim iX As Integer
        Dim iY As Integer

        For iX = 0 To imgSrc.Width - 1
            For iY = 0 To imgSrc.Height - 1
                imgSrc.SetPixel(iX, iY, Color.White)
            Next
        Next

        Dim hiddenCode As String = (Fix(Rnd() * 100000)).ToString
        Session("hiddenCode") = hiddenCode

        Dim imgFont As New Font("Arial", 14)
        Dim imgBrush As New SolidBrush(Color.Black)

        Dim drawFormat As New StringFormat
        Dim imgGraph As Graphics
        imgGraph = Graphics.FromImage(imgSrc)

        Dim x4 As Single = 5.0 + (Rnd() / 1) * (imgSrc.Width - 100)
        Dim y4 As Single = 5.0 + (Rnd() / 1) * (imgSrc.Height - 30)

        imgGraph.DrawString(hiddenCode, imgFont, imgBrush, x4, y4, drawFormat)
        Response.ContentType = "image/jpeg"
        imgSrc.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)

    End Sub 

Default.aspx

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text <> Session("hiddenCode") Then
            Label1.Text = "Wrong Code!"
        Else
            Label1.Text = "Correct Code!"
        End If

End Sub

HTML

<img src="captcha.aspx" alt="noimage" width="110" height="40" name="SICount" id="SICount" />