Browse DevX
Sign up for e-mail newsletters from DevX


How to Spoof-proof Your Logins : Page 3

Who's accessing your Web applications? If you think only humans are registering and logging in, you may be surprised. Learn how to teach your application to differentiate between humans and machines and reject automated registration and login requests.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Exploring the Captcha Code
The main page includes some user input controls, the random image file, and a submit button. The HTML for the page (Index.asp) looks something like this:

<form id="Form1" method="post" runat="server"> <asp:image id= "Image1" runat= "server" ImageUrl= "DrawRandomImage.aspx"> <asp:textbox id="AccessKey" runat="server"></asp:textbox> <asp:Label id= "lblResult" runat= "server"> </asp:Label> </form>

Note that the image control tag (asp:image) is actually a parallel version of a standard HTML image tag except that the URL points to the page that returns the image rather than directly at some image file.

There are two critical parts of the application logic to make this happen. First you need a random string generator:

The following GenerateRandomString function takes an integer parameter that signifies how many letters the random string should hold. The range of acceptable characters is between a-z and A-Z. You can modify the range to include numeric values if you want to create an alpha-numeric string instead.

Public Shared Function GenerateRandomString( ByVal iLength As Integer) As String Dim iStartBC, iEndBC, iStartSC, iEndSC, _ iCount, iTmpC As Integer Dim sRandomString As String Dim rRandom As New Random( _ System.DateTime.Now.Millisecond) ' Convert characters into their integer equivalents ' (their ASCII values) iStartSC = Asc("a") iEndSC = Asc("z") iStartBC = Asc("A") iEndBC = Asc("Z") ' Now loop as many times as is necessary to build ' the string length we want While (iCount < iLength) ' Assign a random number between the MAX ' and MIN values iTmpC = rRandom.Next(iStartBC, iEndSC) If (((iTmpC >= iStartSC) And (iTmpC <= iEndSC) _ Or (iTmpC >= iStartBC) And _ (iTmpC <= iEndBC))) Then sRandomString += Chr(iTmpC) iCount + = 1 End If End While End Function

Thanks for your registration, follow us on our social networks to keep up-to-date