0.1.5 • Published 9 years ago

n-captcha v0.1.5

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

n-captcha

nodejs captcha

How to install

  • brew install pkg-config if you don't have

  • brew install cairo if you don't have

  • npm install n-captcha --save

Config

{
  //verify code length
  textLen: 4,

  //verify code color
  color: '#2897CE',

  //verify code bg-color
  background: '#DFDFDF',

  lineWidth: 3,
  fontSize: 3,
  imageW: 200,
  imageH: 80

  //identify level
  level: 3,

  //bezier Curve color
  bcColor: '#97BFB2',
  beforReqEndHooks: function(){}
}

How to use

if you use express or koa you can use it as middleware

####You server code

var app = express()();
var ncaptcha = require('n-captcha');
app.use(function(req, res, next) {
  if (req.url === '/captcha') {
    var options = {
      beforReqEndHooks: function(verifyCode) {
        if (req.session) req.session.ncaptcha = verifyCode;
        //do something you need
      }
    }
    var verifyCode = ncaptcha(options, res);
  } else {
    next();
  }
})

// route

app.post('/p/doLogin', function() {
  var ncaptcha = req.body.ncaptcha;
  if (ncaptcha !== req.session.ncaptcha) {
    res.json({code: 1000, msg: 'make sure that captcha is right'})
  }
})

####You client code

<html>

<body>
  <img src="/captcha">
</body>

</html>

license

MIT

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago