問題描述
WordPress 不使用會話。
我一直想知道當用户從一個頁面到另一個頁面時,WP 使用什麼機制來維護用户狀態?
最佳解決方案
它使用裸露的 cookie 並存儲登錄狀態信息客户端。
+
=
wordpress_7339a175323c25a8547b5a6d26c49afa=yourusername%7C1457109155%7C170f103ef3dc57cdb1835662d97c1e13;
所有這些餅乾和鹽從哪裏來?
鹽在你的 wp-config.php 文件中:
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
獨特的短語用於 cryptographic hash function
認證 cookie,其名稱存儲在 AUTH_COOKIE 內,通過將 「wordpress_」 與 default-constants.php 中設置的 siteurl 的 md5 和連接而形成。這是默認行為,可以從配置文件內部通過先前設置一些常量來覆蓋。
認證 cookie 是用户名的連接,認證 cookie 有效的時間戳,以及 HMAC,對於那些拉 TL 的人來説,是一種 key-biased 哈希值。三個變量與管道字符串連接。
以下是 HMAC 的構建方式:
$hash = hash_hmac('md5', $username . '|' . $expiration, wp_hash($username . substr($user->user_pass, 8, 4) . '|' . $expiration, $scheme));
這是安全嗎?
根據 this article,這個答案中的大部分信息都來自於它,如果你知道你的獨特的短語,並且如果你的密鑰是獨一無二的,那麼他們知道你的獨特的短語是 200,000,000,000,000,000,000,000,000,000,000 倍,那麼這個星期將會是一個黑社會,要求一個 30 秒的請求。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。

