The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
I've seen several sites using an image-based CAPTCHA program, where you select all the photos with specific content from a random group. I decided to write one, just to see if I could make it work. I have it working, but there's a random bug. Sometimes it will display all the images, sometimes, it will only display 3 on a line (below) instead of 4; but not because an image is missing. It just ignores the for-next loop. I also tried it with a Do While loop, but it ignores that as well on occasion. All the images have displayed at one time or another, so it's not a case of missing images. Can anyone spot the reason?
[IMG]http://i58.tinypic.com/ftppy0.jpg[/IMG]
[IMG]http://i58.tinypic.com/ftppy0.jpg[/IMG]
Code:
<!--#INCLUDE FILE="config.asp"-->
<!--#INCLUDE FILE="includes/inc_header.asp" -->
<%
If Request("Submit") = "Submit" Then
intError = 0 : intIsValid = 0
Dim strR, strV
For i = 1 To 16
strR = "CI" & CStr(i) : strV = "CJ" & CStr(i)
strSql = "SELECT CI_TYPE FROM " & strTablePrefix & "CAP_IMAGES WHERE C_ID=" & Request(strV)
Set rsV=my_Conn.Execute(strSql)
If Not rsV.EOF Then
strType = rsV("CI_TYPE")
rsV.Close
End If
Set rsV = Nothing
If (Request(strR) = "1" And strType <> Request("strImages")) Or (Request(strR) = "0" And strType = Request("strImages")) Then
intError = 1
Exit For
End If
Next
If intError = 1 Then
Response.Write "Improper selection made. <a href=""Javascript:history.go(-1)"">Try again</a>." & vbNewLine
Response.End
Else
intIsValid = 1
'Valid - continue routine goes here
Response.Write "Authenticated."
Response.End
End If
Else
On Error Resume Next
Dim intCap, intCI, strImages, strCII, strCIJ, strIM, intI, intJ
Randomize
IntCap = CInt(((Rnd * 30)+10)/10)
intICap = (5*(intCap-1))+1
strImages=Mid("SignsFruitPizzaCandy",intICap,5)
Response.Write "<form action=""captcha_image.asp"" method=""post"">" & vbNewLine & _
" <input type=""hidden"" name=""strImages"" value=""" & strImages & """ />" & vbNewLine & _
" <table width=""320"" bgColor=""transparent"" border=""0"" cellpadding=""0"" cellspacing=""0"">" & vbNewLine & _
" <tr vAlign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""4"" width=""100%"" bgColor=""" & strTableBorderColor & """>" & vbNewLine & _
" <table width=""100%"" bgColor=""" & strForumCellColor & """ border=""1"" style=""border-collapse:collapse;"" cellpadding=""2"" cellspacing=""0"">" & vbNewLine & _
" <tr vAlign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""4"" width=""100%"" bgColor=""" & strHeadCellColor & """>" & vbNewLine & _
" <font face=""" & strDefaultFontFace & """ size=""" & strHeaderFontSize & """ color=""" & strHeadFontColor & """>Select all images with <b>" & strImages & "</b>.</font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine
strSqlCJ = "UPDATE " & strTablePrefix & "CAP_IMAGES SET CIU=0"
my_Conn.Execute(strSqlCJ),,adCmdText + adExecuteNoRecords
For intI = 0 To 3
Response.Write " <tr vAlign=""top"">" & vbNewLine
intJ = 1
Do While intJ < 5
strSqlC = "SELECT COUNT (CIU) AS CNT FROM " & strTablePrefix & "CAP_IMAGES WHERE CIU=0"
Set rsCnt = my_Conn.Execute(strSqlC)
If Not rsCnt.EOF Then
intCnt = rsCnt("CNT")
rsCnt.Close
End If
Set rsCnt = Nothing
Randomize
intCI = CInt(Rnd * intCnt)
strSql = "SELECT * FROM " & strTablePrefix & "CAP_IMAGES WHERE CIU=0"
Set rsCI = my_Conn.Execute(strSql)
If Not rsCI.EOF Then
rsCI.Move(intCI)
intID = (intI * 4) + intJ
strID = rsCI("C_ID")
strCII = "CI" & CStr(intID) : strCIJ = "CJ" & CStr(intID) : strIM = strImageURL & "CI/" & strID & ".png"
Response.Write " <td vAlign=""top"" bgColor=""" & strForumCellColor & """ nowrap align=""center"" width=""90"">" & vbNewLine & _
" <input type=""hidden"" name=""" & strCIJ & """ value=""" & rsCI("C_ID") & """ />" & vbNewLine & _
" On<input type=""radio"" class=""radio"" style=""background:" & strForumCellColor & ";"" name=""" & strCII & """ value=""1""" & chkRadio(Request(strCII),0,false) & "> Off<input type=""radio"" class=""radio"" style=""background:" & strForumCellColor & ";"" name=""" & strCII & """ value=""0""" & chkRadio(Request(strCII),0,true) & "><br />" & vbNewLine & _
" <image src=""" & strIM & """ height=""70"" width=""70"" style=""border:none; text-decoration:none;"" />" & vbNewLine & _
" </td>" & vbNewLine
strSqlCJ = "UPDATE " & strTablePrefix & "CAP_IMAGES SET CIU = 1 WHERE C_ID=" & rsCI("C_ID")
my_Conn.Execute(strSqlCJ),,adCmdText + adExecuteNoRecords
rsCI.Close
End If
Set rsCI = Nothing
intJ = intJ + 1
Loop
Response.Write " </tr>" & vbNewLine
Next
Response.Write " </table>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr>" & vbNewLine & _
" <td bgColor=""" & strForumCellColor & """ colspan=""4"" width=""100%"" align=""center"" style=""line-height:50%;""><br />" & vbNewLine & _
" <input style=""color:" & strHeadFontColor & "; font-weight:bold; font-family:" & strDefaultFontFace & "; padding:3px 6px 3px 6px; border:1px solid " & strTableBorderColor & "; text-shadow:0px 1px 1px #000; font-weight:bold; text-decoratiOnnone; border-radius:25px; -webkit-border-radius:25px; background:"&strHColor&";"" type=""Submit"" class=""button2"" name=""submit"" value=""Submit"" />" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
"</form>" & vbNewLine
End If
WriteFooter
Function chkRadio(actualValue, thisValue, boltf)
If IsNumeric(actualValue) Then actualValue = cLng(actualValue)
If actualValue = thisValue EQV boltf Then
chkRadio = " checked"
Else
chkRadio = ""
End If
End Function
%>