forked from ss1121/FKP-REST
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha.js
More file actions
44 lines (35 loc) · 986 Bytes
/
captcha.js
File metadata and controls
44 lines (35 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var libs = require('../libs/libs')
var captcha = require('ccap')
function randomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
var maxPos = $chars.length;
var pwd = '';
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function *getCaptcha( opts ){
var options = {
width:200,
height:50,
offset:30,
quality:100,
fontsize:30,
len: 6
}
if(opts)
options = libs.$extend({},options,opts);
options.generate = function(){
return randomString( options.len );
}
var tmp = captcha( options );
var ary = tmp.get();
var txt = ary[0];
var buf = ary[1];
this.sess.captcha = txt;
// return yield {picture: buf};
return buf;
}
module.exports = getCaptcha;