Designing An Insecure Protocol
Here's a little story that demonstrates how easy it is to create an insecure system when you try to roll-your-own security protocol.
ScamAlarm users can report fraudulent web sites using a form on our corporate web site. We decided to use a captcha on this form to defend against "bots" submitting zillions of sites into the system. A captcha is one of those slightly annoying graphics with slanty words/numbers that you find on many web forms, most commonly on forms where users can sign up for free accounts. Here's a sample captcha from the Hotmail signup form:
From a coding point-of-view, here's how most captcha implementations work:

- Use a random number generator to create a phrase to display to the user
- Save that phrase in the user's web session. Give the user a cookie that allows you to find their session on your server.
- Show the user a form to display this captcha and receive data. The form has an image tag with a src like this: captcha.php
- Inside the image generator (captcha.php), lookup the phrase in the user's session and generate the appropriate captcha image
- Validate the typed phrase against the phrase stored in user's session
- Create a secret that's only available in server-side code to the form processor and the image generator
- Generate a unique random number each time we display the form - the seed
- Create the captcha phrase as the first 6 characters of the sha1 hash of our secret + seed.
- Show the form to the user. Include a hidden form field with the seed value. The form has an image tag with a source like this: captcha.php?seed=3284a348dea9d9213
- Inside the image generator (captcha.php), generate the phrase to display (sha1 hash of seed + secret). The seed to use comes as a url parameter.
- Validate the typed phrase against the actual phrase (hash of seed + secret), the seed coming from the hidden form field.