Captcha Creation In Vb.net

Discussion in 'Software' started by cutekiller28, Sep 22, 2008.

  1. cutekiller28

    cutekiller28

    Joined:
    Sep 11, 2008
    Messages:
    4
    Hello frens
    i wanted to create a captcha for my project in vb.net could anybody help me with a code how to create it ....rest i have created a way in which the page main form call this image which doesnt exist formally but it calls my this page jpegimage.vb to get its image but i m still having problems in the session genrated part i hope so .the code is below of main page and the jpegimage.aspx page
    ===========
    main form
    ==========

    Imports System
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    Namespace CaptchaImage
    Public Class _Default
    Inherits System.Web.UI.Page

    Protected Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents CodeNumberTextBox As System.Web.UI.WebControls.TextBox

    Protected WithEvents IMG1 As System.Web.UI.HtmlControls.HtmlImage
    Protected WithEvents tb1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents SubmitButton As System.Web.UI.WebControls.Button
    ' For generating random numbers.
    Private random As New Random

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If Not Me.IsPostBack Then
    Session("CaptchaImageText") = GenerateRandomCode()
    Else

    ' Create a random code and store it in the Session object.

    ' On a postback, check the user input.
    If Me.CodeNumberTextBox.Text = Session("CaptchaImageText").ToString() Then
    ' Display an informational message.
    Me.Label1.CssClass = "info"
    Me.Label1.Text = "Correct!"
    Else
    ' Display an error message.
    Me.Label1.CssClass = "error"
    Me.Label1.Text = "ERROR: Incorrect, try again."

    ' Clear the input and create a new random code.
    Me.CodeNumberTextBox.Text = ""
    Me.Session("CaptchaImageText") = GenerateRandomCode()
    End If
    End If
    End Sub


    '
    ' Returns a string of six random digits.
    '
    Private Function GenerateRandomCode() As String


    Dim s As String = ""
    For i As Integer = 0 To 7
    s = [String].Concat(s, Me.random.[Next](10).ToString())
    Next
    Return s
    End Function

    #Region "Web Form Designer generated code"
    Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
    '
    ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
    '
    InitializeComponent()
    MyBase.OnInit(e)
    End Sub

    ''' <summary>
    ''' Required method for Designer support - do not modify
    ''' the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()

    End Sub
    #End Region
    End Class
    End Namespace

    =========
    jpegimage form
    ========
    Imports System
    Imports System.Collections
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Web
    Imports System.Web.SessionState
    Imports System.Web.UI
    Imports System.Web.UI.WebControls
    Imports System.Web.UI.HtmlControls

    Namespace CaptchaImage
    Public Class JpegImage
    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Create a CAPTCHA image using the text stored in the Session object.
    Dim ci As New CaptchaImage(Session("CaptchaImageText").ToString(), 200, 50, "Scrawl")
    'me. removed
    ' Change the response headers to output a JPEG image.
    Me.Response.Clear()
    Me.Response.ContentType = "image/jpeg"

    ' Write the image to the response stream in JPEG format.
    ci.Image.Save(Me.Response.OutputStream, ImageFormat.Jpeg)

    ' Dispose of the CAPTCHA image object.

    Session("CaptchaImageText").Dispose()
    End Sub

    #Region "Web Form Designer generated code"
    Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
    '
    ' CODEGEN: This call is required by the ASP.NET Web Form Designer.
    '
    InitializeComponent()
    MyBase.OnInit(e)
    End Sub

    ''' <summary>
    ''' Required method for Designer support - do not modify
    ''' the contents of this method with the code editor.
    ''' </summary>
    Private Sub InitializeComponent()
    AddHandler Me.Load, AddressOf Page_Load
    End Sub
    #End Region
    End Class
    End Namespace


    ==========
    please see to it if u could help me out its urgent to be done ..Thanks in advance
     
    cutekiller28, Sep 22, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. guercheLE@gmail.com
    Replies:
    1
    Views:
    1,474
    Digital Photography Now
    Oct 4, 2005
  2. Rev_Jer_Belle_Felcher@hotmail.com

    Does Google Groups always require a Captcha when posting w/a Hotmailbased account?

    Rev_Jer_Belle_Felcher@hotmail.com, Jan 14, 2009, in forum: Computer Support
    Replies:
    1
    Views:
    1,281
    Mike Easter
    Jan 14, 2009
  3. Lawrence D'Oliveiro

    CAPTCHA on Your Home Router!?

    Lawrence D'Oliveiro, May 13, 2009, in forum: NZ Computing
    Replies:
    4
    Views:
    338
    Lawrence D'Oliveiro
    May 20, 2009
  4. RK

    Orkut - SMS Captcha error

    RK, Oct 6, 2009, in forum: Computer Support
    Replies:
    2
    Views:
    604
    Diabolic Preacher
    Oct 8, 2009
  5. Subbu

    Orkut - SMS Captcha error

    Subbu, Jan 27, 2010, in forum: Computer Support
    Replies:
    9
    Views:
    1,251
    softnfurry
    Mar 6, 2010
Loading...

Share This Page