captcha

Simple captcha middleware for Connect

npm install captcha
11 downloads in the last day
43 downloads in the last week
157 downloads in the last month

Captcha

Simple captcha for Connect/Express.

Installation

Via npm:

$ npm install captcha

Usage (for Express 3)

var express = require('express');
var captcha = require('captcha');

var app = express();

app.configure(function(){
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.cookieSession({ secret: 'keyboard-cat' }));
    app.use(captcha({ url: '/captcha.jpg', color:'#0064cd', background: 'rgb(20,30,200)' })); // captcha params
});

app.get('/', function(req, res){
    res.type('html');
    res.end('<img src="/captcha.jpg"/><form action="/login" method="post"><input type="text" name="digits"/></form>'); // captcha render
});

app.post('/login', function(req, res){
    res.type('html');
    res.end('CONFIRM: ' + (req.body.digits == req.session.captcha)); // captcha verify
});

app.listen(8080);
console.log('Web server started.');
npm loves you