1.0.0 • Published 7 years ago
code-identifier v1.0.0
code-identifier
A stateless, valid verification code verification tool based on keygrip.
API
consturctor
opts.intervaltime intervalopts.maxthe max key countopts.appthe name of application, for different app to generate code
const CodeIdentifier = require('code-identifier');
const identifier = new CodeIdentifier({
interval: 51 * 1000,
max: 10,
app: 'my-test-app',
});genCode
generate the code
lenthe length of codeprefixthe prefix to generate code, such astrack cookie,user accountand so on. optional
// { code: '512567', hash: 'flplYRZqe145QQJOlObmW8uNNY8' }
const result1 = identifier.genCode();
// { code: '53684948', hash: 'xixBFHNqGw6YdkPRLrTFR4NkyVI' }
const result2 = identifier.genCode(8);
// { code: '414337', hash: 'mTwUjHLhx_IGJ5FYbRT-np3b2ho' }
const result3 = identifier.genCode(6, 'track cookie');verify
verify the code
codehashthe hash of genCodeprefixthe same as genCode use
// true
const valid1 = identifier.verify('512567', 'flplYRZqe145QQJOlObmW8uNNY8');
// true
const valid2 = identifier.verify('414337', 'mTwUjHLhx_IGJ5FYbRT-np3b2ho', 'track cookie');getCode
Use custom function for get code
identifier.getCode = (len) => crypto.randomBytes(len).toString('hex');
// { code: 'df19f3', hash: 'IfR9zTryXWkA_k93zF2hb0D0YHk' }
const result = identifier.genCode(3);1.0.0
7 years ago