Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

Simple math based CAPTCHA for Classic ASP

$
0
0

I'm building a simple math CAPTCHA to be implemented on a Classic ASP (VBScript) website.

I wrote the code such that each time a request was made to the login page, the session variableCaptchaTries would be incremented by one. When it exceeds MAX_TRIES, the code generates a new math problem for the user to solve.

Everything works fine and the code below lets the user log in successfully but on the 3rd try, even if the user enters the correct username and password along with the correct solution to the CAPTCHA problem, he is redirected back to the login page and is presented with a new CAPTCHA problem to solve.

Every time, the code works correctly for MAX_TRIES-1 times. Please help me fix this.

Dim msg, num1, num2, result, MAX_TRIES
MAX_TRIES = 3

If Session("CaptchaTries") = "" Then
	Session("CaptchaTries") = 1
Else
	Session("CaptchaTries") = CInt(Session("CaptchaTries")) + 1
End If
If CInt(Session("CaptchaTries")) > CInt(MAX_TRIES) Or CInt(Session("CaptchaTries")) = 1 Then
	If CInt(Session("CaptchaTries")) > CInt(MAX_TRIES) Then
		Session("CaptchaTries") = 0
		Response.Redirect "./default.asp"
	End If
	If Not CInt(Session("CaptchaTries") = 0) Then
		Session("num1") = RandomNumber
		Session("num2") = RandomNumber
		Session("result") = CInt(Session("num1"))+CInt(Session("num2"))
	End If
End If
num1 = CInt(Session("num1"))
num2 = CInt(Session("num2"))
result = CInt(Session("result"))

Viewing all articles
Browse latest Browse all 27852

Trending Articles