Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake CAPTCHA images (version 3) in Visual Basic 6
DescriptionThis example shows how to make CAPTCHA images (version 3) in Visual Basic 6.
KeywordsCAPTCHA, Turing test, image, image processing, distort image
CategoriesGraphics, Software Engineering
 

CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) images are those distorted pictures of words that some Web sites make you enter to prove you are a human and not an automated process. The idea is to distort the characters in the image so it would be hard for an optical character recognition (OCR) application to read them but so it would still be easy for a person to read them.

Subroutine DrawCaptcha is quick and simple. It merely draws two strings on top of each other. Usually a human can still read them.

 
' Draw the words overlaid on each other.
Private Sub DrawCaptcha(ByVal pic As PictureBox, ByVal _
    word1 As String, ByVal word2 As String)
Dim x As Single
Dim y As Single

    Randomize

    ' Draw the first word, offset horizontally by a random
    ' amount.
    x = Rnd * (pic.ScaleWidth - pic.TextWidth(word1))
    pic.CurrentX = x
    pic.CurrentY = 0
    pic.Print word1

    ' Draw the second word over the first,
    ' offset vertically a bit and horizontally
    ' by a random amount.
    x = Rnd * (pic.ScaleWidth - pic.TextWidth(word2))
    y = pic.TextHeight(word2) / 3
    If y > pic.ScaleHeight - pic.TextHeight(word2) Then _
        y = pic.ScaleHeight - pic.TextHeight(word2)
    pic.CurrentX = x
    pic.CurrentY = y
    pic.Print word2
End Sub
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated