Validation / Confirmation script code to stop spammers

I have made a validation script some time ago, I use at eg. my directories when people submit new websites and comments. (ASP / VB)
The last couple of months I have been getting some emails asking how it is done, and a thread on digitalpoint have also talked a bit about it, so here it is.
The theory is very easy.
- Have 2 variables, you generate random numbers and put them in
- Have a third Session variabel that containt the result of the sum of the 2 variables.
- Print the 2 variables to the screen and collect the result in an input field
- At submission, check if Session result = Variable1 + Variable 2

intLowNr = 1
intTopNr = 10
ValNr1= Int((intTopNr - intLowNr + 1) * Rnd + intLowNr)
ValNr2= Int((intTopNr - intLowNr + 1) * Rnd + intLowNr)
Session("ValAns") = Int(ValNr1+ ValNr2)
if not(isnumeric(userVal)) then
 fejlkode="<br>Wrong validation code. Must be numeric."
if not (Int(Session("ValAns")) = Int(userVal)) then  
 fejlkode="<br>Wrong validation code. Try again please."  
end if
end if %> 
Validation:<b> <%= ValNr1 %> + <%= ValNr2 %> = <input name="userVal" value=" " >

Dansk blog Engelsk blog
Twitter Claus Heinrich