Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
Tutorial RSS
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Charts
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Controls - Verification code to prevent auto signup in ASP.NET(VB)
Verification code to prevent auto signup in ASP.NET(VB)

ASP.Net 4.0 Tutorials V4
Server Intellect Cloud Hosting

ASP.NET Controls Tutorial

By entering the verification code shown on the web page when a user sign up, the web site or application can prevent automated registrations. This reduces system loads and ensures better performance and security of web site or application. This tutorial will show you how to create the randomly generated verification code in ASP.NET 2.0 and VB.

In order to create a random verification code, we create a method called CreateRandomCode at first

Private Function generateVCode(ByVal CodeLength As IntegerAs String
    Dim VCode As String = String.Empty
    Dim randObj As New Random()
    Dim c As Integer = 63
    For i As Byte = 1 To CodeLength
        c = randObj.Next(35)
        If c >= 10 Then
            c += 7
        End If
        c += 48
        VCode += Chr(c)
    Next
    Return VCode
End Function

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!

Then we generate verification code character string as exported image

Private Function generateHatchStyle() As Drawing.Drawing2D.HatchStyle
    Dim slist As New ArrayList
    For Each style As Drawing.Drawing2D.HatchStyle In System.Enum.GetValues(GetType(Drawing.Drawing2D.HatchStyle))
        slist.Add(style)
    Next

    Dim randObj As New Random()
    Dim index As Integer = randObj.Next(slist.Count - 1)

    Return CType(slist(index), Drawing.Drawing2D.HatchStyle)
End Function

Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!

Use a method GenerateVCodeImage to print image

Private Function GenerateVCodeImage()

    Dim oBitmap As Drawing.Bitmap = New Drawing.Bitmap(90, 35)
    Dim oGraphic As Drawing.Graphics = Drawing.Graphics.FromImage(oBitmap)
    Dim foreColor As System.Drawing.Color
    Dim backColor As System.Drawing.Color

    Dim sText As String = generateVCode(6)
    Dim sFont As String = "Comic Sans MS"


    foreColor = System.Drawing.Color.FromArgb(220, 220, 220)
    backColor = System.Drawing.Color.FromArgb(190, 190, 190)

    Dim oBrush As New Drawing.Drawing2D.HatchBrush(CType(generateHatchStyle(), Drawing.Drawing2D.HatchStyle), foreColor, backColor)

    Dim oBrushWrite As New Drawing.SolidBrush(Drawing.Color.Red)

    oGraphic.FillRectangle(oBrush, 0, 0, 100, 50)
    oGraphic.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

    Dim oFont As New Drawing.Font(sFont, 14)
    Dim oPoint As New Drawing.PointF(5.0F, 4.0F)

    oGraphic.DrawString(sText, oFont, oBrushWrite, oPoint)

    Response.ContentType = "image/jpeg"
    oBitmap.Save(Response.OutputStream, Drawing.Imaging.ImageFormat.Jpeg)
    oBitmap.Dispose()

    Return sText
End Function

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

Transfer function on Page_load

Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load
    Dim code As String = GenerateVCodeImage()
    Session("VCode") = code
End Sub

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!



 
  Developer Resources







Server Intellect Rocks