Page 1 of 1

Creating a Captcha Validation in Visual Basic Captcha validation check using lines, loops, random numbers. Rate Topic: -----

#1 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 50
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Post icon  Posted 21 January 2009 - 11:01 PM

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.

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


Picture1.print generated1




(3)Making them scratched(using lines)


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

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



I hope this helped

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a Captcha Validation in Visual Basic

#2 trie_ari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-May 09

Posted 20 May 2009 - 07:41 AM

:blink: :blink: :blink:

please, show in detailed or make a sample project.

thanks for your help :)

This post has been edited by trie_ari: 20 May 2009 - 07:42 AM

Was This Post Helpful? 0
  • +
  • -

#3 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Posted 21 May 2009 - 12:16 AM

A few things.
- It should be this:
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. :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1