code-identifier
A stateless, valid verification code verification tool based on keygrip
.
API
consturctor
opts.interval
time intervalopts.max
the max key countopts.app
the name of application, for different app to generate code
const CodeIdentifier = ;const identifier = interval: 51 * 1000 max: 10 app: 'my-test-app';
genCode
generate the code
len
the length of codeprefix
the prefix to generate code, such astrack cookie
,user account
and so on. [optional]
// { code: '512567', hash: 'flplYRZqe145QQJOlObmW8uNNY8' }const result1 = identifier; // { code: '53684948', hash: 'xixBFHNqGw6YdkPRLrTFR4NkyVI' }const result2 = identifier; // { code: '414337', hash: 'mTwUjHLhx_IGJ5FYbRT-np3b2ho' }const result3 = identifier;
verify
verify the code
code
hash
the hash of genCodeprefix
the same as genCode use
// trueconst valid1 = identifier; // trueconst valid2 = identifier;
getCode
Use custom function for get code
identifier crypto; // { code: 'df19f3', hash: 'IfR9zTryXWkA_k93zF2hb0D0YHk' }const result = identifier;