WebHashcash
Beta

WebHashcash Installation

WebHashcash can be installed on virtually any collaborative web site, such as a weblog, discussion forum, or wiki, to guard against automated content posting, fake user registration, or ballot stuffing.

It is compatible with all server-side languages, including Perl, PHP, ASP, and JSP.

Installation is an easy, three-step process. First, you must insert the WebHashcash JavaScript code into your web form's HTML. Second, copy the WebHashcash.jar file to your web server. Finally, modify the target page of your form to check for valid hashcash stamps and act accordingly.

  1. Insert the JavaScript into your web form
  2. Copy the Java applet to your web server
  3. Modify server-side code on target page

Step 1: Insert the JavaScript into your web form

All of the following code must be inserted between the <form ...> and </form> tags of the appropriate form on your web page.

A — Include this block of code anywhere inside the form:

<script type="text/javascript" src="http://www.davidsj.com/webhashcash/embed-before.js"></script>
<script type="text/javascript"><!--
    function WHCConfig() {
        WHCResource = "<resource>";
        WHCSubmitButton = document.<form name>.<submit button name>;
        WHCPostage = <postage>;
    }
//--></script>

That is the code for the WebHashcash status display. It will appear like this on your page:

You can customize its appearance like you would any other page element by surrounding it with web formatting tags.

That code also contains all custom parameters for WebHashcash. You will need to modify it as follows:

  1. Replace <resource> with a unique identifying string for your web form.

        Example: WHCResource = "john_doe_blog_comments";

  2. Replace <form name> with the name of your web form as found in the name property of its <form ...> tag, and replace <submit button name> with the name of your submit button as found in the name property of its <input ...> tag.

        Example: WHCSubmitButton = document.addcomment.submit;

  3. That allows WebHashcash to enable and disable the submit button as appropriate.

  4. Replace <postage> with the amount of postage your form requires. There are two ways to do this:

  5. · Specify your postage relative to the default postage (currently 22).

        Example: WHCPostage = WHCDefaultPostage + 5;

    The advantage of that approach is that as computers become more powerful, more postage will be necessary to discourage spammers. WebHashcash's default postage will gradually increase with time.

    · If you prefer, you can instead specify an exact amount of postage.

        Example: WHCPostage = 18;

Step 2: Copy the Java applet to your web server

Download the WebHashcash.jar file, and place it on your web server. WebHashcash will not work otherwise.

If the WebHashcash.jar file is located in a separate directory from your web form, you must insert this additional parameter into the JavaScript code from Step 1B:

WHCAppletDirectory = "<HTTP path to WebHashcash.jar directory>";

Example:

WHCAppletDirectory = "/mydirectory/appletfolder/";

Step 3: Modify server-side code on target page

The process of verifying WebHashcash stamps is very easy. However, how your target page responds in the case of invalid stamps is up to you.

In some situations, legitimate users will not be able to generate WebHashcash stamps due to browser incompatibility. In those cases, you may choose to allow some limited functionality (e.g. on a discussion forum, you might allow un-stamped comments to go through after moderator approval). See Step 1B — Further Customization to allow form submission in the case of failed stamp generation.

Below is skeleton code for determining stamp validity. You will need to fill in the remaining functionality as appropriate for your web site. Please select the language that your site uses below:

Demonstration Form

Click here to view a demonstration form, with visible WebHashcash stamps.

You can also try out the form with either Perl or PHP targets, and examine the code for those targets.