1.9.1 • Published 4 years ago
jsonpasswordtoken v1.9.1
node-jsonpasswordtoken
Install
$ npm install jsonpasswordtoken
Usage
jsonpasswordtoken.sign(payload,secret,expiryTime,iv)
(Synchronous) Return a token.
Options:
payload
secret
(secret must be 32bit long)expiryTime
(Optional, defaults to 7day, format will be 4,'day/minute')iv
(iv must be 16bit long)
If payload
is not a buffer or a string, it will be coerced into a string
using JSON.stringify
.
Example
const signature = jsonpasswordtoken.sign({name:'jsonpasswordtoken'},'testhmkiltyofgntghylqwertyuilmnv',[5,'day'],'absvuitlgrthifbr');
//it will return d587f74978e9fc8bc25e47cd2b8d2e2b18fc9590b60935e25f997946036b1dbc4534d83474d4e690b236eda46a1dc9a2e5ab261b660795208a41b2e67fbd5b08ad9d08b9a60e36a17a904c4037ed3a08.PY2GqN0Rlkr_uSYGEzH_HJsWpWWyFDnzCXJp1LvTH-Q
jsonpasswordtoken.verify(token, secret, iv)
(Synchronous) Returns Object of verified true
or false
for whether a signature matches a
secret or iv.
token
is a JPT Token.
Example
const signature = jsonpasswordtoken.verify('d587f74978e9fc8bc25e47cd2b8d2e2b18fc9590b60935e25f997946036b1dbc4534d83474d4e690b236eda46a1dc9a2e5ab261b660795208a41b2e67fbd5b08ad9d08b9a60e36a17a904c4037ed3a08.PY2GqN0Rlkr_uSYGEzH_HJsWpWWyFDnzCXJp1LvTH-Q','testhmkiltyofgntghylqwertyuilmnv','absvuitlgrthifbr');
// Returns an object with two child properties, e.g.
// { decryptedData: { name: 'jsonpasswordtoken' }, verified: true }
jsonpasswordtoken.encryptPass(secret,password)
Returns the encrypted password.
Example:
const encryptedPassword = jsonpasswordtoken.encryptPass("test123456", "123456789");
jsonpasswordtoken.verifyPass(secret,encryptedpassword,password)
Returns true
or false
Example:
const isVerifiedPassword = jsonpasswordtoken.verifyPass("test123456","dbd3c46e07b2eb78a7cca5ca0154b7872c490288c1c133f86840a4a848b04e34", "123456789");
License
ISC