Page 1 of 1

Simple Captcha Application

Posted: Sat Mar 30, 2013 2:54 am
by 3aaBrSbeel
This Simple Captcha Application doesn't need Internet to load it's Captcha but it generates a random image for you to answer.

Screeny:
3-30-2013 10-44-35 AM.png
Okay, you need the following elements:
  • 2 Button
    1 PictureBox
    1 TextBox
Button 1 will be the Submit button. Checking if the answer is correct or incorrect.
Button 2 will be the one refreshing a new generated image for you to answer.
TextBox you need this to answer lmao;
PictureBox you need this to show the image lmao;

Okay, let's start. Add this code below your Public Class.
This code will create the question and the lines so it's a bit harder to read which makes it a bit challenging.
Code: Select all
    Private cAnswer As String = Nothing

    Private Function genQuestion() As String
        Dim cOperators As String() = {"+", "-"}
Start:
        Dim p1 As Integer = New Random().Next(1, 9)
        Dim p2 As Integer = New Random().Next(1, 9)

        If p1 = p2 Then GoTo Start

        Dim cOperator As String = cOperators(New Random().Next(0, cOperators.Length))

        Select Case cOperator
            Case "+"
                cAnswer = p1 + p2
                If cAnswer <= 0 Then GoTo Start
            Case "-"
                cAnswer = p1 - p2
                If cAnswer <= 0 Then GoTo Start
        End Select
        Return String.Format("{0}{1}{2}", p1, cOperator, p2)
    End Function
    Private Sub generateLines(ByVal G As Graphics)
        If Not G Is Nothing Then
            Dim R As New Random()
            Dim lineBrush As New SolidBrush(Color.LightGray)

            For i% = 0 To 9
                G.DrawLines(New Pen(lineBrush, R.Next(1, 2)), New Point() {New Point(0, R.Next(0, 60)), New Point(200, R.Next(0, 60))})

            Next
        End If
    End Sub

    Private Function generateImage() As Image
        Dim B As New Bitmap(200, 60)
        Using G As Graphics = Graphics.FromImage(B)
            With G
                .Clear(Color.White)
                .DrawString(genQuestion(), New Font("Segoe UI", 20), Brushes.Black, New Rectangle(0, 0, 200, 60), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
            End With
            generateLines(G)
        End Using
        Return B
    End Function
So next, we will be coding the submit button or Button 1, this will submit your answer. lmao;
Code: Select all
Select Case TextBox1.Text
            Case Is = cAnswer

                MessageBox.Show("Correct!", "Correct!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                PictureBox1.Image = generateImage()
                TextBox1.Clear()
            Case Else
                MessageBox.Show("Incorrect!", "Incorrect!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                PictureBox1.Image = generateImage()
                TextBox1.Clear()
        End Select
        TextBox1.Clear()
Button 2 and Form_Load will be the same code. Add this line of code to Button 2 and Form_Load.
Code: Select all
PictureBox1.Image = generateImage()
When you are done, debug it and test. Thanks for reading and testing this thread, I'm pretty sure you've learned something new.

Re: Simple Captcha Application

Posted: Sat Mar 30, 2013 5:28 am
by Shim
nice one mate , keep it up

Re: Simple Captcha Application

Posted: Sat Mar 30, 2013 12:57 pm
by benji_19994
It looks heaps like this did you copy and paste it? you should give the credits to the author

http://www.hackforums.net/showthread.php?tid=3365830

Re: Simple Captcha Application

Posted: Sun May 26, 2013 3:49 pm
by master3395
benji_19994 wrote:
It looks heaps like this did you copy and paste it? you should give the credits to the author

http://www.hackforums.net/showthread.php?tid=3365830
Both was made at the same time, might be the same owner.

This was made

Postby 3aaBrSbeel ยป Sat Mar 30, 2013 3:54 am

And the one on the other site was made

03-30-2013, 03:45 AM (This post was last modified: 03-30-2013 03:50 AM by Hexology.)

Might be the same owner.