Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Tenho sofrido com invasão de spammers nos formulários de meu site. Ouvi falar numa idéia interessante que é o CAPTCHA INVERTIDO e gostaria de implementar.
Seria criar no formulário um campo invísivel ao internauta através de CSS. Este campo deve permanecer em branco e como o usuário não o vê, não tem como preencher. Desta forma, como os robôs costumam preencher todos os campos para garantir que o formulário seja validado, o formulário seria anulado.
Preciso portanto de um script que valide o formulário somente se o campo invisível não for preenchido.
Será que isso existe?
Ok, obrigado pelo resposta. Mas gostaria de tentar essa solução, pois me disseram que dá certo.
Preciso de um script que invalide um formulário, caso um determinado campo seja preenchido.
Alguém pode me ajudar?
E qual linguagem server-side você vai usar ? php, asp, java..
>
E qual linguagem server-side você vai usar ? php, asp, java..
ASP. Obrigado!
Melhor método para prevenir Spam
captcha.asp
<%@LANGUAGE="VBSCRIPT"%>
<%
'Gerar imagens para fazer um teste CAPTCHA
FontMap = Array(_
split("13,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9",",") ,_
split("14,5#45,4#64,&2,&2,3#32#33,&5,2#42#42,2#34#32,2#102,1#121,1#36#31,&11,#3*8#3",",") ,_
split("11,#83,#101,#34#31,&3,&3,&1,&2,#34#4,#35#3,&9,&8,&2,#9*2",",") ,_
split("11,4#61,2#9,1#44#2,1#36#1,#38,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("12,#84,#102,#34#41,#35#31,#3*6#3,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("9,#9,&1,#36,&3,&3,#81,&6,&3,&3,&3,&3,&1,&1",",") ,_
split("9,#9,&1,#3*6,&3,&3,&1,&1,&3,&3,&3,&3,&3,&3",",") ,_
split("13,4#7,2#11,1#45#3,1#38#1,#3,#3,#34#6,&7,#37#3,1#36#3,1#54#3,&2,&1",",") ,_
split("11,#3*5#3,&1,&1,&1,&1,#11,&6,&1,&1,&1,&1,&1,&1",",") ,_
split("7,#7,#7,*2#3,&3,&3,&3,&3,&3,&3,&3,&3,&1,&1",",") ,_
split("8,2#6,&1,5#3,&3,&3,&3,&3,&3,&3,&3,*4#4,#7,#6",",") ,_
split("12,#35#4,#34#4,#33#4,#32#4,#32#3,#31#3,#7,#8,&5,#33#3,#34#3,#3*5#3,&1",",") ,_
split("9,#3,#3,#3,#3,#3,#3,#3,#3,#3,#3,#3,#9,#9",",") ,_
split("13,#37#3,#45#4,&2,#53#5,&4,#61#6,#31#21#21#3,#31#51#3,#32#32#3,&9,#37#3,&11,&11",",") ,_
split("11,#44#3,#53#3,&2,#62#3,&4,#31#31#3,&6,#32#6,&8,#33#5,&10,#34#4,#3*5#3",",") ,_
split("13,4#5,2#9,1#43#4,1#35#3,#3*7#3,&5,&5,&5,&5,&4,&3,&2,&1",",") ,_
split("10,#8,#9,#33#4,#34#3,&4,&4,&3,&2,#7,#3,#3,#3,#3",",") ,_
split("13,3#6,2#8,1#34#3,1#26#2,#28#2,&5,&5,#24#13#2,#24#22#2,1#24#4,&3,2#10,3#62#2",",") ,_
split("12,#8,#9,#34#3,&3,&3,#33#4,&2,&1,#32#4,#33#3,&3,#34#4,#35#4",",") ,_
split("11,3#6,1#9,#44#2,#36#1,#4,#8,&2,3#8,7#4,#17#3,#34#4,#10,*1#7",",") ,_
split("11,#11,&1,*4#3,&3,&3,&3,&3,&3,&3,&3,&3,&3,&3,&3",",") ,_
split("11,#35#3,&1,&1,&1,&1,&1,&1,&1,&1,&1,#43#4,1#9,3#5",",") ,_
split("14,#38#3,1#36#3,&2,1#35#4,2#34#3,&5,3#32#3,&7,&7,4#6,&10,&10,*5#4",",") ,_
split("17,#34#34#3,&1,#33#53#3,1#32#21#22#3,&4,1#31#31#31#3,&6,1#31#23#21#3,&8,2#53#5,&10,2#45#4,&12",",") ,_
split("14,#46#4,1#44#4,2#42#4,3#32#3,3#8,4#6,5#4,&6,&5,&4,&3,&2,&1",",") ,_
split("13,#45#4,1#35#3,2#33#3,2#41#4,3#31#3,3#7,4#5,5#3,&8,&8,&8,&8,&8",",") ,_
split("10,#10,&1,6#4,5#4,5#3,4#3,3#4,3#3,2#3,1#4,#4,&1,&1",",") ,_
split("10,3#43,1#81,1#32#31,#34#3,&4,&4,&4,&4,&4,&4,&3,&2,&1",",") ,_
split("9,3#33,&1,#63,&3,3#3*3,&5,&5,&5,&5,&5,&5,#9,&12",",") ,_
split("10,1#63,#82,#23#41,#15#31,6#31,&5,5#32,4#42,3#43,2#44,1#4*5,#10,&12",",") ,_
split("11,1#82,#101,#35#3,#17#3,7#31,3#62,3#71,7#4,8#3,&4,#34#4,&2,1#73",",") ,_
split("12,6#42,5#52,&2,4#21#32,3#31#32,2#32#32,1#33#32,#34#32,#12,&9,7#32,&11,&11",",") ,_
split("11,1#10,&1,1#37,&3,1#82,1#91,7#4,8#3,&8,#17#3,#34#31,#101,1#7*3",",") ,_
split("11,4#61,2#81,1#46,1#37,#31#52,#101,#34#4,#35#3,&8,&8,1#33#31,1#91,3#53",",") ,_
split("11,#11,&1,7#4,7#31,6#41,6#32,5#33,4#43,4#34,3#44,3#35,2#36,1#4*6",",") ,_
split("11,2#72,1#91,#34#4,#35#3,#43#31,1#82,&1,1#31#51,&4,&4,#43#4,&2,2#63",",") ,_
split("11,3#53,1#91,1#33#31,#35#3,&4,&4,#44#3,1#10,2#51#3,7#31,6#41,1#82,1#64",",") _
)'linha deve terminar com _
'# inicio ColorMap
const BmpColorMap = "dffeff000c851700eceeee006c363600da644a00"
ColorMap = Array(_
split("00,01,01",",") ,_
split("02,03,03",",") ,_
split("00,04,04",",") _
)'fim ColorMap
'#Auto calculado variáveis
dim ImageWidth, ImageHeight, arrTextWidth(), TextHeight, LeftMargin, arrTopMargin(), CursorPos
dim BmpEndLine, BColor, TColor, NColor
dim i, j, k, x, y
'#Editável consts e variáveis
dim Bitmap(25,130) '[Height,Width]
const CodeLength = 6 'código comprimento(Max:8)
const CodeType = 1 '0[Random números], 1 [Random chars e números], 2 [Fake palavra]
const CharTracking = 2 'Configure o monitoramento entre dois personagens
const RndTopMargin = true'Aleatório margem superior cada caracter
const NoiseEffect = 2 '0 [nenhum], 1 [esquema], 2 [aleatória conhecimentos linhas], 3 [aleatória fundo linhas], 4 [1 e 3 (Recommed máximo NoiseLine = 4)]
const NoiseLine = 7 'Baixos valores tornam fácil OCR, altos valores diminuem legibilidade
const MinLineLength = 6 'Mínimo ruído linha comprimento
const SessionName = "ASPCAPTCHA" 'Onde armazenar o seu código seguro
'#Subroutinas e functions
function CreateGUID(valLength)
if CodeType = 1 then
strValid = "A0B1C2D3E4F5G6H7I8J9K8L7M6N5O4P3Q2R1S0T1U2V3W4X5Y6Z7"
else
strValid = "0516273849"
end if
tmpGUID = vbNullString
tmpChr = vbNullString
Randomize(Timer)
for cGUID=1 to valLength
do
tmpChr = Mid(strValid, Int(Rnd(1) * Len(strValid)) + 1, 1)
loop while CStr(tmpChr) = CStr(Right(tmpGUID,1))
tmpGUID = tmpGUID & tmpChr
Next
CreateGUID = tmpGUIDfunction FakeWord(valLength)
arrChars = Array("AEIOU", "BCDFGHJKLMNPQRSTVWXYZ")
cVowel = 0
cConsonant = 0
tmpWord = vbNullString
Randomize(Timer)
for cWord=1 to valLength
if (cWord=2) or ((valLength > 1) and (cWord = valLength)) then
ixChars = 1-ixChars
elseif (cVowel < 2) and (cConsonant < 2) then
ixChars = Int(Rnd(1) * 2)
elseif (cVowel < 2) then
ixChars = 0
elseif (cConsonant < 2) then
ixChars = 1
end if
Pattern = arrChars(ixChars)
tmpWord = tmpWord & Mid(Pattern, Int(Rnd(1) * Len(Pattern)) + 1, 1)
if ixChars = 0 then
cVowel = cVowel + 1
cConsonant = 0
else
cVowel = 0
cConsonant = cConsonant + 1
end if
next
FakeWord = tmpWord
end function
function RndInterval(valMin,valMax)
Randomize(Timer)
RndInterval = Int(((valMax - valMin + 1) * Rnd()) + valMin)
end function
function GetCharMap(valChr)
dim i, j
j = 0
for i=1 to UBound(FontMap(0))
if CStr(FontMap(0)(i)) = CStr(valChr) then
j = i
exit for
end if
next
if j > 0 then
GetCharMap = FontMap(j)
else
GetCharMap = Array(0)
end if
end function
sub WriteCanvas(byval valChr, byval valTopMargin)
dim i, j, k, curPos, tmpChr, arrChrMap, strPixMap, drawPixel, pixRepeat
'encontrar char mapa
arrChrMap = GetCharMap(valChr)
if UBound(arrChrMap) < 1 then
exit sub
end if
'write char
for i=1 to UBound(arrChrMap)
'obter mapa pixel linha ativa
strPixMap = arrChrMap(i)
if Left(strPixMap,1) = "&" then
j = Mid(strPixMap,2)
if (IsNumeric(j) = true) then
strPixMap = arrChrMap(CInt(j))
else
strPixMap = vbNullString
end if
end if
strPixMap = Trim(strPixMap)
'desenhar pixel
curPos = CursorPos
drawPixel = false
pixRepeat = vbNullString
for j=1 to Len(strPixMap)
tmpChr = Mid(strPixMap,j,1)
if (IsNumeric(tmpChr) = true) and (j < Len(strPixMap)) then
pixRepeat = pixRepeat & tmpChr
else
if IsNumeric(tmpChr) = true then
pixRepeat = pixRepeat & tmpChr
end if
'desenhar pixel
if (drawPixel = true) and (IsNumeric(pixRepeat) = true) then
for k=1 to CInt(pixRepeat)
curPos = curPos + 1
Bitmap((valTopMargin + i),curPos) = TColor
next
elseif IsNumeric(pixRepeat) = true then
curPos = curPos + CInt(pixRepeat)
end if
if tmpChr = "#" then
drawPixel = true
else
drawPixel = false
end if
pixRepeat = vbNullString
end if
next
next
end sub
sub PrepareBitmap(valSecureCode)
dim i, j
'imagem dimensoes
ImageWidth = UBound(Bitmap,2)
ImageHeight = UBound(Bitmap,1)
'char e text largura
redim arrTextWidth(CodeLength)
arrTextWidth(0) = 0
for i=1 to CodeLength
arrTextWidth(i) = CInt(GetCharMap(Mid(secureCode,i,1))(0))
arrTextWidth(0) = arrTextWidth(0) + arrTextWidth(i)
next
arrTextWidth(0) = arrTextWidth(0) + ((CodeLength - 1) * CharTracking)
'text altura
TextHeight = CInt(FontMap(0)(0))
'left margin
LeftMargin = Round((ImageWidth - arrTextWidth(0)) / 2)
'top margin
redim arrTopMargin(CodeLength)
arrTopMargin(0) = Round((ImageHeight - TextHeight) / 2)
if RndTopMargin = true then
for i=1 to CodeLength
arrTopMargin(i) = RndInterval(Int(arrTopMargin(0) / 2),(arrTopMargin(0) + Round(arrTopMargin(0) / 2)))
next
else
for i=1 to CodeLength
arrTopMargin(i) = arrTopMargin(0)
next
end if
'cor selecção
i = RndInterval(0,UBound(ColorMap))
BColor = ColorMap(i)(0)
NColor = ColorMap(i)(1)
TColor = ColorMap(i)(2)
'Aplicar fundo efeito
if NoiseEffect = 3 then
AddNoise()
end if
'escreve texto
for i=1 to CodeLength
'calcular cursor pos
CursorPos = 0
for j=(i-1) to 1 step -1
CursorPos = CursorPos + arrTextWidth(j) + CharTracking
next
CursorPos = LeftMargin + CursorPos
'escrever activa char
WriteCanvas Mid(secureCode,i,1),arrTopMargin(i)
next
end sub
sub DrawLine(x0, y0, x1, y1, valClr)
dim m, b, dx, dy
if (NoiseEffect = 4) and (Bitmap(y0,x0) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(y0,x0) = clrNoise
dx = x1 - x0
dy = y1 - y0
if Abs(dx) > Abs(dy) then
m = (dy / dx)
b = y0 - (m * x0)
if dx < 0 then
dx = -1
else
dx = 1
end if
do while x0 <> x1
x0 = x0 + dx
if (NoiseEffect = 4) and (Bitmap(Round((m * x0) + B),x0) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(Round((m * x0) + B),x0) = clrNoise
loop
elseif dy <> 0 then
m = (dx / dy)
b = x0 - (m * y0)
if dy < 0 then
dy = -1
else
dy = 1
end if
do while y0 <> y1
y0 = y0 + dy
if (NoiseEffect = 4) and (Bitmap(y0,Round((m * y0) + B)) = TColor) then
clrNoise = vbNullString
else
clrNoise = valClr
end if
Bitmap(y0,Round((m * y0) + B)) = clrNoise
loop
end if
end sub
sub AddNoise()
dim median, i, j, x0, y0, x1, y1, dx, dy, dxy
if NoiseEffect = 1 then
clrNoise = vbNullString
else
clrNoise = NColor
end if
for i=1 to NoiseLine
x0 = RndInterval(1,ImageWidth)
y0 = RndInterval(1,ImageHeight)
x1 = RndInterval(1,ImageWidth)
y1 = RndInterval(1,ImageHeight)
'Verificar linha comprimento mínimo
dx = Abs(x1 - x0)
dy = Abs(y1 - y0)
median = Round(Sqr((dx dx) + (dy dy))/2)
if median < MinLineLength then
dxy = MinLineLength - median
if x1 < x0 then
dx = -1
else
dx = 1
end if
if y1 < y0 then
dy = -1
else
dy = 1
end if
for j=1 to dxy
if ((x1 + dx) < 1) or ((x1 + dx) > ImageWidth) or ((y1 + dy) < 1) or ((y1 + dy) > ImageHeight) then
exit for
end if
x1 = x1 + dx
y1 = y1 + dy
next
end if
'Draw linha noise
DrawLine x0,y0,x1,y1,clrNoise
next
end sub
function FormatHex(byval valHex,byval fixByte,fixDrctn,valReverse)
fixByte = fixByte * 2
tmpLen = Len(valHex)
if fixByte > tmpLen then
tmpFixHex = String((fixByte - tmpLen),"0")
if fixDrctn = 1 then
valHex = valHex & tmpFixHex
else
valHex = tmpFixHex & valHex
end if
end if
if valReverse = true then
tmpHex = vbNullString
for cFrmtHex=1 to Len(valHex) step 2
tmpHex = Mid(valHex,cFrmtHex,2) & tmpHex
next
FormatHex = tmpHex
else
FormatHex = CStr(valHex)
end if
end function
sub SendHex(valHex)
for cHex = 1 to Len(valHex) step 2
Response.BinaryWrite ChrB(CByte("&H" & Mid(valHex,cHex,2)))
next
end sub
sub SendBitmap()
if (ImageWidth mod 4) <> 0 then
BmpEndLine = String((4-(ImageWidth mod 4))*2,"0")
else
BmpEndLine = vbNullString
end if
BmpInfoHeader = Array("28000000","00000000","00000000","0100","0800","00000000","00000000","120B0000","120B0000","00000000","00000000")
BmpInfoHeader(1) = FormatHex(Hex(ImageWidth),4,0,true)
BmpInfoHeader(2) = FormatHex(Hex(ImageHeight),4,0,true)
BmpInfoHeader(6) = FormatHex(Hex((ImageHeight ImageWidth) + (ImageHeight (Len(BmpEndLine) / 2))),4,0,true)
BmpInfoHeader(9) = FormatHex(Hex(Len(BmpColorMap)/8),4,0,true)
BmpInfoHeader(10) = BmpInfoHeader(9)
BmpHeader = Array("424D","00000000","0000","0000","00000000")
BmpHeader(1) = FormatHex(Hex((Len(Join(BmpHeader,"")) / 2) + (Len(Join(BmpInfoHeader,"")) / 2) + (Len(BmpColorMap) / 2) + (ImageHeight ImageWidth) + (ImageHeight (Len(BmpEndLine) / 2))),4,0,true)
BmpHeader(4) = FormatHex(Hex((Len(Join(BmpHeader,"")) / 2) + (Len(Join(BmpInfoHeader,"")) / 2) + (Len(BmpColorMap) / 2)),4,0,true)
Response.Clear
Response.Buffer = True
Response.ContentType = "image/bmp"
Response.AddHeader "Content-Disposition", "inline; filename=captcha.bmp"
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
SendHex(Join(BmpHeader,""))
SendHex(Join(BmpInfoHeader,""))
SendHex(BmpColorMap)
for y=ImageHeight to 1 step -1
for x=1 to ImageWidth
tmpHex = Bitmap(y,x)
if tmpHex = vbNullString then
SendHex(BColor)
else
SendHex(tmpHex)
end if
next
SendHex(BmpEndLine)
next
Response.Flush
end sub
%>
<%
'#Gerar captcha
if CodeType < 2 then
secureCode = CreateGUID(CodeLength)
else
secureCode = FakeWord(CodeLength)
end if
Session(SessionName) = secureCode
PrepareBitmap(secureCode)
if (NoiseEffect > 0) and (NoiseEffect <> 3) then
AddNoise()
end if
SendBitmap()
%>
test.asp
<%@LANGUAGE="VBSCRIPT"%>
<%
function TestCaptcha(byval valSession, byval valCaptcha)
dim tmpSession
valSession = Trim(valSession)
valCaptcha = Trim(valCaptcha)
if (valSession = vbNullString) or (valCaptcha = vbNullString) then
TestCaptcha = false
else
tmpSession = valSession
valSession = Trim(Session(valSession))
Session(tmpSession) = vbNullString
if valSession = vbNullString then
TestCaptcha = false
else
valCaptcha = Replace(valCaptcha,"i","I")
if StrComp(valSession,valCaptcha,1) = 0 then
TestCaptcha = true
else
TestCaptcha = false
end if
end if
end if<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<title>CAPTCHA Exemplo</title>
<style type="text/css"> font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
</style>
<script language="javascript">
function RefreshImage(valImageId) {
var objImage = document.images[valImageId];
if (objImage == undefined) {
return;
}
var now = new Date();
objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="400" border="1" align="center">
<tr>
<td colspan="2" align="center"><strong>CAPTCHA Exemplo</strong></td>
</tr>
<tr>
<td width="261">CAPTCHA Imagem</td>
<td width="123"><img id="imgCaptcha" src="captcha.asp" /><br /><a href="java script:void(0)" onclick="RefreshImage('imgCaptcha')">Mudar Imagem</a></td>
</tr>
<tr>
<td>Escreva os caracteres da imagem acima</td>
<td><input name="captchacode" type="text" id="captchacode" size="10" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="btnTest" id="btnTest" value="Test Input" /></td>
</tr>
<%
if not IsEmpty(Request.Form("btnTest")) then
Response.Write("<tr><td colspan=""2"" align=""center"">")
if TestCaptcha("ASPCAPTCHA", Request.Form("captchacode")) then
Response.Write("<b style=""color:#00CC33"">O código que você digita verificada.</b>")
else
Response.Write("<b style=""color:#FF0000"">Você digitou o código errado.</b>")
end if
Response.Write("</td></tr>" & vbCrLf)
end if
%>
</table>
</form>
</body>
</html>
qq captcha que você faça, é melhor que não dependa de javascript...
veja com a tua linguagem de programação... para validar