A jQueryplugin
that enhances an input field to help reduce automated form submission.
The current version is 2.0.1 and is available
under the MIT licence.
For more detail see the documentation reference page.
Or see a minimal page that you could
use as a basis for your own investigations.
This plugin is designed to help overcome automated form submission by
requiring a "real person" to identify text made up of dots.
The entered value is compared on the server with the generated value
to determine whether processing should continue.
The real person functionality can easily be added to an input field
with appropriate default settings.
You can also remove the real person functionality if it is no longer required.
To complete the form processing on the server, you compare the
hash value computed from the text entered by the user with the
hash value generated on the client. If the two match, then you
have a "real person" submitting the form and can continue.
The following server side implementations of the hash algorithm are available:
class FormController < BaseController
# POST /form
# POST /form.json
def create
realPerson = params[:realPerson]
realPersonHash = params[:realPersonHash]
if !realPerson.nil? && !realPersonHash.nil? && Integer(rpHash(realPerson)) == Integer(realPersonHash)
# Accepted
else
# Rejected
end
end
private
def rpHash (defaultReal)
hash = 5381
if !defaultReal.nil?
defaultReal.upcase!
defaultReal.length.times{ |i| hash = ((shift_32 hash, 5) + hash) + defaultReal[i].ord }
end
return hash
end
def shift_32 x, shift_amount
shift_amount &= 0x1F
x <<= shift_amount
x &= 0xFFFFFFFF
if (x & (1<<31)).zero?
x
else
x - 2**32
end
end
end
Python
Thanks to Sérgio H. Berlotto Jr.
import numpy as np
#------------------------------
def rpHash(person):
hash = 5381
value = person.upper()
for caracter in value:
hash = (( np.left_shift(hash, 5) + hash) + ord(caracter))
hash = np.int32(hash)
#-----------------------------
if rpHash(request.form['realPerson']) == request.form['realPersonHash']:
# Accepted
else:
# Rejected
In the Wild
This tab highlights examples of this plugin in use "in the wild".
e2e.ee provides end-to-end instant messaging that protects your privacy.
The plugin is used on the Get Started form.
To add another example, please contact me (wood.keith{at}optusnet.com.au)
and provide the plugin name, the URL of your site, its title,
and a short description of its purpose and where/how the plugin is used.
Quick Reference
A full list of all possible settings is shown below.
Note that not all would apply in all cases. For more detail see the
documentation reference page.
$(selector).realperson({
length: 6, // Number of characters to use
regenerate: 'Click to change', // Instruction text to regenerate
hashName: '{n}Hash', // Name of the hash value field to compare with,
// use {n} to substitute with the original field name
dot: '*', // The character to use for the dot patterns
dots: $.realperson.defaultDots, // The dot patterns per letter in chars
chars: $.realperson.alphabetic // The characters allowed */
});
$.salt // A salt value to add to the entered text, or the selector for its field
$.realperson.alphabetic // Set of alphabetic characters
$.realperson.alphanumeric // Set of alphabetic and numeric characters
$.realperson.defaultDots // The default set of dots that make up each character
$.realperson.setDefaults(settings) // Change settings for all instances
$(selector).realperson('option', settings) // Change the instance settings
$(selector).realperson('option', name, value) // Change a single instance setting
$(selector).realperson('option', name) // Retrieve an instance setting
$(selector).realperson('enable') // Enable the control
$(selector).realperson('disable') // Disable the control
$(selector).realperson('destroy') // Remove the real person functionality
Usage
Include the jQuery library in the head section of your page.