11-06-2010, 06:16 PM
(This post was last modified: 11-06-2010, 06:25 PM by Resistance.)
A CAPTCHA or Captcha (pronounced /ˈkæptʃə/) is a type of challenge-response test used in computing to ensure that the response is not generated by a computer. The process usually involves one computer (a server) -- WOW, WOW, WOW. A SERVER??? |||||| asking a user to complete a simple test which the computer is able to generate and grade.
Welcome to my tutorial on how to generate Captcha without using pictures, internet connection or anything external that the application has to access; as long as you get a human response? Correct? I believe so. Today I will show you a nice feature that almost every computer can do in the world, generate a random number!... -.-'
We will be using that method in our captcha, and the best part about offline captcha in a VB form my way, is that there is NO need to refresh it for the following reasons:
_____________________________________________
Lets proceed. First open a form up, and have the following created:Welcome to my tutorial on how to generate Captcha without using pictures, internet connection or anything external that the application has to access; as long as you get a human response? Correct? I believe so. Today I will show you a nice feature that almost every computer can do in the world, generate a random number!... -.-'
We will be using that method in our captcha, and the best part about offline captcha in a VB form my way, is that there is NO need to refresh it for the following reasons:
- Unreadable Letters
- Long and Pointless Words
- Never loaded correctly
- Half the Captcha loaded
_____________________________________________
- 3 Buttons
- 3 Reasonable Icons for Refresh, Close, and Confirm/Submit User Input, if you want to be fancy.
- 3 TextBoxes
- Ability to follow my Tutorial
1. Now Open up VB6, VB8, VB9, VB10 or whatever...
2. Select new project, WindowsApplication...
3. Name it whatever you want, etc...
4. Add the following above. And now for the pre-step.
5. Each Button should be named, Generate New Captcha Offline, Submit New Captcha Offline, and Exit Captcha Offline.
6. One of Each textbox should have the following values: >Enter Captcha Number Here<, 999999999, and Nothing as in Blank. Make the Blank one big and obvious so they know what to enter as Captcha.
---
Now for the Code.
PublicClass + Form1_Load:
Code:
Public Class Form1
Dim charactersDisallowed As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,<>./?; :'{}[]=+-_)(*&^%$#@!~`|\uç▲ìα▲╜KÄ╤ZlÆ╘¦«¨©÷ ¢¡¬®¯°±²³´µ¶·¸¹£¤¥»¼½¾¿"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
KeyPreview = True
Try
Dim Random As New Random
TextBox1.Text = Random.Next(TextBox2.Text)
Catch ex As Exception
MsgBox("Invalid Characters/No Numerical Value Detected", 16, "Fatal Error")
End Try
TextBox2.Visible = False 'This is what gives a digit limit for random captcha.
TextBox1.Enabled = False 'Disables TextBox so User cannot copy and paste the captcha.
TextBox1.ReadOnly = True 'Disables so user cannot edit the captcha.
End Sub
Generate New Captcha Button Code:
Code:
Dim Random As New Random
TextBox1.Text = Random.Next(TextBox2.Text)
Submit Captcha Button Code:
Code:
If TextBox3.Text = TextBox1.Text Then
MsgBox("Captcha entered successfuly!", 64, "Human Detected!")
'Other Code should be put here if the user enters the captcha correctly, like Form2.Show()
Else
MsgBox("Your Kind is Not wanted Here, Robot!", 48, "Robot Detected!")
'here add code that tells the user they have entered it incorrectly, I called them a robot for fun.
End If
Exit Captcha Button Code:
Code:
End
Captcha Input TextBox (Where you put the captcha):
Code:
Dim theText As String = TextBox3.Text
Dim Letter As String
For x As Integer = 0 To TextBox3.Text.Length - 1
Letter = TextBox3.Text.Substring(x, 1)
If charactersDisallowed.Contains(Letter) Then
theText = theText.Replace(Letter, String.Empty)
End If
Next
TextBox3.Text = theText
TextBox3.Select(TextBox3.Text.Length, 0)
Captcha Input TextBox (Auto Submit Captcha on Enter Key):
Code:
Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Enter Then
Button3_Click(Nothing, Nothing)
End If
End Sub
In the end, it should look somewhat like this:
FINALIZED RESULTS!!!
Download the Application as an Example
Enjoy and don't forget to say thanks... Your all very welcome in advanced!
For:
ѕмии™, he gave me an idea by posting his tutorial!