我尝试在我的节点中实现。js应用程序是验证用户cookie是否有效的一种方法。我在互联网上找到了一些帖子,他们很好地向我解释了这些事情,但当我尝试实现它时,我使用了Node的WordPress身份验证模块。js,我发现它不起作用了。
经过一些搜索,我发现WordPress 4.0 出于某种原因:
现在,如果logged_in cookie name is still hashed with MD5, 哈希salted密码现在为sha256 (or sha1 if impossible) encrypted, 考虑WordPress函数中的这部分代码wp_generate_auth_cookie() :
// If ext/hash is not present, compat.php\'s hash_hmac() does not support sha256.
$algo = function_exists( \'hash\' ) ? \'sha256\' : \'sha1\';
$hash = hash_hmac( $algo, $user->user_login . \'|\' . $expiration . \'|\' . $token, $key );
我不确定,但正如我在代码中发现的那样,自WordPress 4.0以来,登录的salt不再使用,但在WP\\U Session\\U令牌中定义了令牌的用法,如下所示:
$manager = WP_Session_Tokens::get_instance( $user_id );
$token = $manager->create( $expiration );
所以我想知道:
is there a way from wordpress 4.0 to verify logged_in cookie ?
最合适的回答,由SO网友:Nicolas Frbezar 整理而成
好的,我找到了解决方案。
事实上,我没有注意到,there is always the hashed mdp, 但目前,logged\\u in cookie的结构如下:
%登录%|%超时%|%sessionId%|%已过期%
而不是:
%登录%|%超时%|%passhached%
自wordpress 4.0和wp\\u session\\u cookie集成以来,auth方法与之前相同,但只有两个变化:
- the sessionid is introduced 在cookie和密钥计算中,登录的cookie加密为sha256 or if not possible sha1所以有一个加密过程的方案
KEY = md5_HMAC(%login%|%caracter 8-12 of the passhached in database%|%timeout%|%sessionId% , LOGGED_IN_KEY.LOGGED_IN_SALT);
RESULT = sha256_HMAC(%login%|%timeout%|%sessionId% , KEY);
// RESULT = sha1_HMAC(%login%|%timeout%|%sessionId% , KEY); only if sha256 is not supported
现在,要批准连接,登录的\\u cookie的pass hached需要与RESULT相同