0

我想查询我的 Redis 服务器以获取用户名的匹配密码。我怎样才能做到这一点?我对 Redis 和 Node 的经验都很少,所以我找不到存储这些的密钥。

非常感谢任何帮助!

4

1 回答 1

1

查看文件 /src/routes/authentication.js。那里有Auth.login函数,它获取用户名、密码作为参数。然后你在用户对象上有getUidByUserslug函数,它首先被调用并从名为'userslug:uid'的redis哈希返回你的用户ID(_uid)(查看/src/user.js文件db.getObjectField(' userslug:uid ',userslug , 回调);函数)。下一步是通过用户 ID 从'user:' + uid hash 获取用户,存储在 redis 中。这是使用 db.getObjectFields('user:' + uid, ['password', 'banned'], next); authenticate.js 文件中的函数。

以下是Auth.login函数:

Auth.login = function(req, username, password, next) {
    if (!username || !password) {
        return next(new Error('[[error:invalid-password]]'));
    }

    var userslug = utils.slugify(username);
    var uid;

    async.waterfall([
        function(next) {
            user.getUidByUserslug(userslug, next);
        },
        function(_uid, next) {
            if (!_uid) {
                return next(new Error('[[error:no-user]]'));
            }
            uid = _uid;
            user.auth.logAttempt(uid, req.ip, next);
        },
        function(next) {
            db.getObjectFields('user:' + uid, ['password', 'banned'], next);
        },
        function(userData, next) {
            if (!userData || !userData.password) {
                return next(new Error('[[error:invalid-user-data]]'));
            }
            if (userData.banned && parseInt(userData.banned, 10) === 1) {
                return next(new Error('[[error:user-banned]]'));
            }
            Password.compare(password, userData.password, next);
        },
        function(passwordMatch, next) {
            if (!passwordMatch) {
                return next(new Error('[[error:invalid-password]]'));
            }
            user.auth.clearLoginAttempts(uid);
            next(null, {uid: uid}, '[[success:authentication-successful]]');
        }
    ], next);
};
于 2015-03-30T07:57:16.230 回答