Using Math to Detect and Slow Down Spamming Technique

AID: 7311
  • Status: Published

1140 points

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math. While this method is not one-hundred-percent foolproof, it gives a general idea of how we can slow down spammers a bit.

I have used many recaptcha codes like Lyla Captcha, Recaptcha, Coldfusion's own Captcha, and many others free and commercial captcha techniques. They all are not fully foolproof. Therefore, I find the Math method good as it does not involve image creation or something similar. Just create some simple math and you are done with it! If you want to play more with it, you can always do the following:

1. Follow Ben Nadel's post on Math De spamming Technique
2. Make the math Calculation more Complex
3. Add the reload functionality to this – e.g., build an Image of the calculation as new image and reload it again with a new image on same page.
 
A very tricky technique, though we will just be playing with the random numbers and sending the details the users to solve the math operation. While this technique uses only the multiplication, addition, and subtraction methods only, while more advanced techniques can be added like modulus, division, and other such operations.

But to keep it simple, I have included the following files I am using to make this work. I welcome all you suggestions and comments if you find any way to enhance the code!

Code Samples


1a. The first file, Application.cfm:
<!---  You can change this value to make it more complex --->
<cfset request.Requestedhash = "!!!@$$5656%%00(())"> 
                                    
1:
2:

Select allOpen in new window



1b. If you have Application.cfc, then use in the OnRequestStart() method:
<!--- You can change this value to make it more complex --->
<cfset request.Requestedhash = "!!!@$$5656%%00(())"> 
                                    
1:
2:

Select allOpen in new window



2. The next file is the our main file where we want to use the Spam Code
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check for Spam</title>
<cfinclude template="getnew.cfm">
</head>
<body>
<cfif isDefined('form.chk')>
   <cfif hash(form.ColorTest & request.Requestedhash) eq form.weightInPounds>
      <cfset a = "The Spam test Passed">
   <cfelse>
      <cfset a = "The Spam test Failed">
   </cfif>
</cfif>
<cfform method="post" action="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
  <cfif isDefined('a')>
  <tr><td colspan="2" align="center"><cfoutput><div style="color:red; text-decoration:underline; font-weight:bold;">#a#</div></cfoutput></td></tr>
  </cfif>
  <tr>
    <td align="right">Verify&nbsp;:&nbsp;</td>
    <td><cfoutput><strong>#store#</strong>
      <cfset saltedValue = Hash(Fix(sum) & request.Requestedhash)>
      <input type="hidden" name="weightInPounds" value="#saltedValue#">
	  </cfoutput></td>
  </tr>
  <tr>
    <td width="25%" align="right">Spam Test&nbsp;:&nbsp;</td>
    <td><input type="text" name="ColorTest" id="ColorTest" /></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td><input type="submit" name="chk" id="chk" value="Check For Spam" /><br />
    Don not use (-) if the value of the result is in minus</td>
  </tr>
</table>
</cfform>
</body>
</html>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:

Select allOpen in new window



3. Then at last, the page code of GetNew.cfm, which generates the spam check code:
<cfset value1 = RandRange(1,10)>
<cfset value2 = RandRange(9,20)>
<cfset randomList = "*|+|-">
<cfset randomInt = randrange(1, listLen(randomList, "|"))>
<cfset id = ListGetAt(randomList, randomInt, "|")>
<cfif value1 LT value2>
  <cfset sum = PrecisionEvaluate('#value2##id##value1#')>
  <cfset store = value2 & id & value1>
  <cfelse>
  <cfset sum = PrecisionEvaluate('#value1##id##value2#')>
  <cfset store = value1 & id & value2>
</cfif>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window



I think you will find the code useful. We are using here some built-in functions of ColdFusion like ListGetAt, RandRange, PrecisionEvaluate, which helped us to build our match equation; therefore, read the 'livedocs' for more information!

Thanks!
Asked On
2011-09-01 at 05:49:14ID7311
Tags

Coldfusion

Topic

Cold Fusion Markup Language

Views
611

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top ColdFusion Language Experts

  1. _agx_

    268,859

    Guru

    2,000 points yesterday

    Profile
    Rank: Genius
  2. gdemaria

    184,144

    Guru

    1,800 points yesterday

    Profile
    Rank: Genius
  3. SidFishes

    87,866

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  4. myselfrandhawa

    58,872

    Master

    0 points yesterday

    Profile
    Rank: Guru
  5. dgrafx

    36,068

    0 points yesterday

    Profile
    Rank: Sage
  6. pravinasar

    26,318

    0 points yesterday

    Profile
    Rank: Genius
  7. leakim971

    19,600

    0 points yesterday

    Profile
    Rank: Genius
  8. maestropsm

    15,340

    0 points yesterday

    Profile
    Rank: Guru
  9. ansudhindra

    13,300

    0 points yesterday

    Profile
    Rank: Wizard
  10. Zvonko

    12,264

    0 points yesterday

    Profile
    Rank: Genius
  11. micropc1

    10,200

    0 points yesterday

    Profile
    Rank: Master
  12. COBOLdinosaur

    9,800

    200 points yesterday

    Profile
    Rank: Genius
  13. TechHelpr08210

    9,700

    0 points yesterday

    Profile
  14. cyberdyne_dev

    9,500

    0 points yesterday

    Profile
  15. srikanthmadishetti

    8,601

    0 points yesterday

    Profile
    Rank: Guru
  16. brijeshchauhan

    8,468

    0 points yesterday

    Profile
    Rank: Guru
  17. Proculopsis

    8,200

    0 points yesterday

    Profile
    Rank: Sage
  18. kaufmed

    7,468

    0 points yesterday

    Profile
    Rank: Genius
  19. JohnHowlett

    6,000

    0 points yesterday

    Profile
  20. DaveBaldwin

    5,750

    0 points yesterday

    Profile
    Rank: Genius
  21. digicidal

    4,600

    0 points yesterday

    Profile
    Rank: Guru
  22. erikTsomik

    4,500

    0 points yesterday

    Profile
    Rank: Sage
  23. HainKurt

    4,500

    0 points yesterday

    Profile
    Rank: Genius
  24. mplungjan

    4,400

    0 points yesterday

    Profile
    Rank: Savant
  25. sedgwick

    4,000

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame