[VB.NET]Creating a Basic Captcha String

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

1UP

Member
Oct 9, 2014
24
10
63
This was something I pulled from a test program I was messing with. I was writing an application to send some information to a remote database and to prevent "flooding" I could write in a captcha. Granted I would never include this because of how simple it is, it was rather easy.

First off our function to create the random string of letters.
Code:
  Private Function generateCaptchaString()
  Dim rand As New Random
  Dim currentLetter As String
  Dim captchaString As String = ""
  For i = 0 To 6
  currentLetter = ChrW(rand.Next(Asc("A"), Asc("Z") + 1))
  captchaString &= currentLetter
  Next

  Return captchaString
  End Function

Then the code for creating the image with the string as apart of it.
Code:
  'Set captchaText to what is generated in the function generateRandomString
  Dim captchaText As String = generateCaptchaString()

  'Creating a bitmap in memory
  Dim captchaBitmap As New Bitmap(200, 40)

  'Creating a Graphic so we can manipulate how the image will look
  Dim captchaGraphic As Graphics = Graphics.FromImage(captchaBitmap)

  Dim captchaFont As New Font("Arial", 14)

  'Set the Text color
  Dim captchaForeColor As New SolidBrush(Color.Blue)

  'Set the background color
  Dim captchaBackgroundColor As New SolidBrush(Color.Yellow)

  captchaGraphic.FillRectangle(captchaBackgroundColor, 0, 0, Width, Height)
  captchaGraphic.DrawString(captchaText, captchaFont, captchaForeColor, 5.0F, 5.0F)

  pict_Captcha.Image = captchaBitmap
 
  • Like
Reactions: Younis
General chit-chat
Help Users
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Shadow2323 is our newest member. Welcome!
  • Chat Bot:
    Ahmed_818x is our newest member. Welcome!
  • Chat Bot:
    hiiokoyf is our newest member. Welcome!
  • Chat Bot:
    menetao is our newest member. Welcome!
  • Chat Bot:
    Jaydawgjr1985 is our newest member. Welcome!
  • Chat Bot:
    tjisbadatps3 is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Eratrix is our newest member. Welcome!
  • Chat Bot:
    Bluerazz is our newest member. Welcome!
  • Chat Bot:
    gandajogador is our newest member. Welcome!
  • Chat Bot:
    Lindows has posted a new profile post.
  • Chat Bot:
    eleontino is our newest member. Welcome!
  • @ Fretyeco192321:
    Does anyone know a public GTA V Legacy working Mod Menu
  • @ Fretyeco192321:
    I'm trynna run Missions & Heist with it
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    rskmoto is our newest member. Welcome!
  • Chat Bot:
    youb13 is our newest member. Welcome!
  • @ youb13:
    Hi
  • @ QM|T_JinX:
    hi
  • Chat Bot:
    Christo has joined the room.
      Chat Bot: Christo has joined the room.