add random string to token gen
add crc to utils
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ehason/auth",
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.4",
|
||||
"description": "User auth lib",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user