add random string to token gen

add crc to utils
This commit is contained in:
lik
2019-09-04 10:46:51 +08:00
parent 9fced9b8b6
commit 679c784ead
5 changed files with 156 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ function AuthToken(redisdb) {
AuthToken.prototype.genToken = async function(userData, expiresSeconds) {
// 生成系统内部的user token
let hash = crypto.createHash('md5');
hash.update(JSON.stringify(userData) + Date());
hash.update(JSON.stringify(userData) + Date() + Math.random());
let userToken = hash.digest('hex');
// 缓存到redis
@@ -99,9 +99,9 @@ AuthToken.prototype.getTokenData = async function (userToken) {
};
let tokenInstance = null;
module.exports = function getTokenInstance(redisPort, redisHost, db) {
module.exports = function getTokenInstance(redisdb) {
if (!tokenInstance) {
tokenInstance = new AuthToken(redisPort, redisHost, db);
tokenInstance = new AuthToken(redisdb);
}
return tokenInstance;
};

View File

@@ -1,6 +1,6 @@
{
"name": "@ehason/auth",
"version": "1.2.2",
"version": "1.2.4",
"description": "User auth lib",
"main": "index.js",
"scripts": {