School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,109 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,003 people online right now. Registration is fast and FREE... Join Now!




Creating a Captcha Validation in Visual Basic

 
Reply to this topicStart new topic

> Creating a Captcha Validation in Visual Basic, Captcha validation check using lines, loops, random numbers.

Nikhil_07n
Group Icon



post 21 Jan, 2009 - 10:01 PM
Post #1


Concept

The basic thing we are goin' to do is the following steps:

1) Generating Random characters.
2)Printing them in a picture box.
3) Making them scratched.

(1)Generating Random Characters

NOTE:Make sure that you write "Randomize" Command in the form_load event.

CODE

dim fck1,fck2,fck3,fck4 as integer

fck1 = Int((91 - 65 + 1) * Rnd + 65)
fck3 = Int((91 - 65 + 1) * Rnd + 65)
fck2 = Int((123 - 97 + 1) * Rnd + 97)
fck4 = Int((123 - 97 + 1) * Rnd + 97)
gen1 = Chr(fck1) & Chr(fck2) & Chr(fck3) & Chr(fck4)
generated1 = Chr$(fck1) & " " & Chr(fck2) & " " & Chr(fck3) & " " & Chr(fck4)



Explanation : Fck 1,2,3 and 4 are variables for storing ascii code of the character which is generated randomly.

65 to 91 is the ascii code of Capital A-Z
97 to 123 is ascii code of Small(lower case) a-z

so, gen1 will contain a FOUR letter word. This we are using for checking purposes

generated1 is the text to be shown in the picture box...(its used because spaces look nice)

(2)Printing in Picture Box

CODE


Picture1.print generated1



(3)Making them scratched(using lines)

CODE


For i = 1 To 60
X1 = (3000 * Rnd) + 1
X2 = (3000 * Rnd) + 1
x3 = (3000 * Rnd) + 1
x4 = (3000 * Rnd) + 1
Y1 = (3000 * Rnd) + 1
Y2 = (3000 * Rnd) + 1
y3 = (3000 * Rnd) + 1
y4 = (3000 * Rnd) + 1
z1 = (3000 * Rnd) + 1
z2 = (3000 * Rnd) + 1
z3 = (3000 * Rnd) + 1
z4 = (3000 * Rnd) + 1
a1 = (3000 * Rnd) + 1
a2 = (3000 * Rnd) + 1
a3 = (3000 * Rnd) + 1
a4 = (3000 * Rnd) + 1
b1 = (3000 * Rnd) + 1
b3 = (3000 * Rnd) + 1
b2 = (3000 * Rnd) + 1
b4 = (3000 * Rnd) + 1
Picture1.Line (X1, X2)-(x3, x4), vbWhite
Picture1.Line (Y1, Y2)-(y3, y4), vbWhite
Picture1.Line (z1, z2)-(z3, z4), vbWhite
Picture1.Line (a1, a2)-(a3, a4), vbWhite
Picture1.Line (b1, b2)-(b3, b4), vbWhite
Next i



Explanation : In the variables a1234, b1234, z1234,x1234,y1234 we are genrating a number between 1 to 3000(Because 3000x3000 is dimension of picture box). These are the req. coordinates.

Now we just simply print the lines in the the picture box with these coordinates.

NOTE : To increase the intensity of lines, just increase the upper bound of loop.

The result printed will be Four letters with some(or more) scratches, hardly readable.

Validation Part

CODE

If Text1.Text = gen1 Then
MsgBox ("correct")
Else
MsgBox ("wrong")
End If


I hope this helped
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

trie_ari
*



post 20 May, 2009 - 06:41 AM
Post #2

blink.gif blink.gif blink.gif

please, show in detailed or make a sample project.

thanks for your help smile.gif

This post has been edited by trie_ari: 20 May, 2009 - 06:42 AM
Go to the top of the page
+Quote Post

firebolt
Group Icon



post 20 May, 2009 - 11:16 PM
Post #3
A few things.
- It should be this:
CODE

Picture1.Print gen1

'<<OR>>

If Text1.Text = generated1 Then


-I think its best to place Picture1.Cls under the possibly click event.
-and you should have centered the text placement.

But nice tutorial. icon_up.gif
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 12:53PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month