CaptCha

« Older   Newer »
  Share  
MatteoJug
CAT_IMG Posted on 13/5/2008, 21:41     +1   -1




Premessa: per info Wikipedia

O fatto un piccolo programma che crea dei Captcha e controlla se l'utente ha inserito correttamente o no le lettere ( è case insensitive)

CODICE
;By MatteoJug
#include <ScreenCapture.au3>
Global $text=StringMid(_Random_Str(8),1,8);Max 8 caratteri
dim $part[StringLen($text)],$Font_Total=_GetFont()
$GUI = GUICreate("Captcha", 220, 166, 193, 125)
GUISetBkColor(0xFFFFFF)
$gra = GUICtrlCreateGraphic(0, 0, 220, 100)
GUICtrlSetBkColor(-1,-2)
$pic = GUICtrlCreatePic("",0, 0, 220, 100)
GUICtrlSetState(-1,32)
$input = GUICtrlCreateInput("", 0, 112, 217, 21)
$check = GUICtrlCreateButton("Controlla", 0, 136, 110, 25, 0)
$refresh = GUICtrlCreateButton("Aggiorna", 110, 136, 110, 25, 0)
GUISetState(@SW_SHOW)
_SetRanBKGra()
for $i=0 to UBound($part)-1
$part[$i]=GUICtrlCreateLabel(StringMid($text,$i+1,1),220/UBound($part)*$i,Random(0,50,1),220/UBound($part),50)
GUICtrlSetFont(-1,Random(9,28,1),Random(1,2,1)*400,_Random_Att(),$Font_Total[Random(0,UBound($Font_Total)-1,1)])
GUICtrlSetBkColor(-1,-2)
Next
BlockInput(1)
WinSetOnTop($GUI,"",1)
$pos=WinGetPos($GUI)
_ScreenCapture_Capture(@ScriptDir & "\Curr_Captcha.bmp",$pos[0]+3,$pos[1]+29,$pos[0]+220+3,$pos[1]+100+29,False)
WinSetOnTop($GUI,"",0)
BlockInput(0)
GUICtrlSetImage($pic,@ScriptDir & "\Curr_Captcha.bmp")
for $i=0 to UBound($part)-1
GUICtrlDelete($part[$i])
Next
GUICtrlDelete($gra)
GUICtrlSetState($pic,16)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
case $check
if StringReplace(stringLower(GUICtrlRead($input))," ","")==StringReplace(StringLower($text)," ","") then
MsgBox(0,"","Corretto")
Else
MsgBox(0,"","Errato")
EndIf
case $refresh
_Refresh(_Random_Str(7))
GUICtrlSetData($input,"")
EndSwitch
WEnd
Func _Random_Str($_number)
$_ret=""
for $i=1 to $_number
$_ret&=Chr(Random(65,90))
Next
Return $_ret
EndFunc
Func _Refresh($text_new)
Global $text=StringReplace(StringMid($text_new,1,8)," ","");Max 8 caratteri
dim $part[StringLen($text)]
BlockInput(1)
WinSetOnTop($GUI,"",1)
GUICtrlSetState($pic,32)
$gra = GUICtrlCreateGraphic(0, 0, 220, 100)
GUICtrlSetBkColor(-1,-2)
_SetRanBKGra()
for $i=0 to UBound($part)-1
$part[$i]=GUICtrlCreateLabel(StringMid($text,$i+1,1),220/UBound($part)*$i,Random(0,50,1),220/UBound($part),50)
GUICtrlSetFont(-1,Random(9,28,1),Random(1,2,1)*400,_Random_Att(),$Font_Total[Random(0,UBound($Font_Total)-1,1)])
GUICtrlSetBkColor(-1,-2)
Next
$pos=WinGetPos($GUI)
_ScreenCapture_Capture(@ScriptDir & "\Curr_Captcha.bmp",$pos[0]+3,$pos[1]+30,$pos[0]+220+3,$pos[1]+100+30,False)
WinSetOnTop($GUI,"",0)
GUICtrlSetImage($pic,@ScriptDir & "\Curr_Captcha.bmp")
for $i=0 to UBound($part)-1
GUICtrlDelete($part[$i])
Next
GUICtrlDelete($gra)
GUICtrlSetState($pic,16)
BlockInput(0)
EndFunc
Func _SetRanBKGra()
for $i=0 to 40
GUICtrlSetGraphic($gra,8,Random(0,255^3,1),Random(0,255^3,1))
GUICtrlSetGraphic($gra,2,Random(0,220,1),Random(0,100,1))
Next
GUICtrlSetGraphic($gra,22)
EndFunc
Func _Random_Att()
$_ran=Random(1,8,1)
Switch $_ran
case 1
Return 0
case 2
Return 2
case 3
Return 4
case 4
Return 8
case 5
Return 6
case 6
Return 12
case 7
Return 10
case 8
Return 14
EndSwitch
EndFunc
Func _GetFont()
Local $_Dir=@WindowsDir & "\Fonts",$_ret[1]
$_first=FileFindFirstFile($_Dir & "\*.TTF")
While 1
$_check=FileFindNextFile($_first)
if @error then Return $_ret
ReDim $_ret[UBound($_ret)+1]
$_ret[UBound($_ret)-1]=$_check
WEnd
EndFunc

Pareri?
PS: se a qualcuno interessa se ne potrebbe fare anche un UDF
 
Top
Jac123
CAT_IMG Posted on 14/5/2008, 06:52     +1   -1




.."case sensitive"
 
Top
MatteoJug
CAT_IMG Posted on 14/5/2008, 14:30     +1   -1




Case insensitive (contrario di case sensitive)
 
Top
lknokl
CAT_IMG Posted on 14/5/2008, 14:33     +1   -1




molto interessante come idea ^^ complimenti
 
Top
I.Ren
CAT_IMG Posted on 14/5/2008, 14:38     +1   -1




buono, moolto buono!
 
Top
4 replies since 13/5/2008, 21:41   192 views
  Share