Captcha is one of the way through which the unknown visitors or the hackers will be prevented with great ease.
This topics contains the example program of Captcha text in VB.NET. The CAPTHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart. This will reduce the hackers, spam attackers, and fake visitors or entries from website.
Example Screenshot: In the following example we create one label to display random generated captcha text, Refresh button to change captcha text, Text box to enter captcha text for trusted users and Register button to verify the entered text valid or not.

Source Code :
System.Drawing.Drawing2D is the two dimensional and vector graphics functionality. The randomly generated captcha text stores in str string variable. In the button it validates txtReg text box and str variable. The random generated text stores in str variable. Maimum it stores 5 characters. The the program converts text to bit map image. Same code applied in the form load and btn referesh button.
Imports System.Drawing.Drawing2D
Public Class Form1
Dim str As String
Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnReg.Click
If txtReg.Text = str Then
MsgBox("Register Success")
Else
MsgBox("Register Faile")
End If
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
Dim NumCaptcha As String = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
str = ""
Dim R As New Random
For i As Integer = 0 To 5
str = str + NumCaptcha(R.Next(0, 60))
Next
Dim b As New Bitmap(274, 71, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
Dim Hb As New HatchBrush(HatchStyle.DottedDiamond, Color.FromArgb(255, 128, 0), Color.Black)
g.DrawString(str, New Font("Curlz MT", 40, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5)
picCaptcha.Image = b
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim NumCaptcha As String = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
str = ""
Dim R As New Random
For i As Integer = 0 To 5
str = str + NumCaptcha(R.Next(0, 60))
Next
Dim b As New Bitmap(274, 71, Imaging.PixelFormat.Format32bppArgb)
Dim g As Graphics = Graphics.FromImage(b)
Dim Hb As New HatchBrush(HatchStyle.DottedDiamond, Color.FromArgb(255, 128, 0), Color.Black)
g.DrawString(str, New Font("Curlz MT", 40, FontStyle.Strikeout, GraphicsUnit.Point), Brushes.White, 5, 5)
picCaptcha.Image = b
End Sub
End Class
Project title: Captcha text in VB.NET
Programming Language: VB.NET
The applications of using CAPTCHA are as follows:
- Prevent spam: This application will help prevention of spam comment in blogs.
- Website registration: This will help in protecting the websites during the registration process.
- Differentiate: The CAPTCHA will help in differentiating between the humans and the robots with great ease.
- Email address: The CAPTCHA will also help in protecting the email addresses from the scrapers.
- Dictionary attacks: This can also help in preventing the dictionary attacks without any difficulty.
- Online polling: This can also help in detecting whether the vote casted through online is by a human or a robot.
- Web pages: This will help in protecting the confidential information of the web pages.
- Prevent bots: The CAPTCHA can help in preventing the bots that will be used in the social networking sites or during some form registration.
Download Example Code:
Video Tutorial of Captcha Text:

