![](/img/trans.png)
[英]Wordpress password how to compare user password to wordpress user table password?
[英]How to sanitize user password information in WordPress?
我正在我的 WordPress 網站上的自定義注冊表單中獲取用戶名、電子郵件和密碼。 我正在使用sanitize_user()
sanitize_email()
用戶名, sanitize_user()
sanitize_email()
電子郵件地址。
例如:
$username = sanitize_user( $username );
$email = sanitize_email( $email );
我應該如何清理用戶輸入的密碼? 我能想到的只是sanitize_text_field( $pass )
但我確定這不是正確的方法。
參考:
消毒不一定能保護您免受注射。 為了防止這種情況,您需要使用准備好的語句 - 或者在 WordPress 的情況下,使用$wpdb 類。
清理只是去除無效字符,在您上面給出的情況下,它會刪除用戶名中不允許的字符,或有效電子郵件地址中不允許的字符。 密碼允許使用許多不同的字符類型,因為這就是它們“強大”的原因,因此您不想將它們刪除。
如果您使用wp_insert_user()
創建一個 WP 用戶,那么您無論如何都不需要對其進行清理,該函數將為您處理所有這些。
如前所述,您可以使用sanitize_text_field()
函數。 它可能會導致一些帶有特殊字符等的瘋狂密碼出現問題。
不過應該沒問題。
wp_insert_user()
消毒狀態和過濾器關閉 (2021) WordPress 5.7
wp_insert_user()
和user_pass
默認:
wp_hash_password()
散列user_pass
。不應消毒。
wp_insert_user()
和user_login
默認:
sanitize_user()
清理user_login
。empty()
過濾user_login
。mb_strlen
過濾user_login
。 (最多 60 個字符)。username_exists()
將user_login
與用戶進行比較。user_login
通過illegal_user_logins
非法用戶登錄。 wp_insert_user()
和user_nicename
默認情況下:
sanitize_user()
清理user_nicename
。user_nicename
通過mb_strlen
。 (最多 50 個字符)。sanitize_title()
清理user_nicename
。 wp_insert_user()
和user_email
默認情況下:
empty()
過濾user_email
。strcasecmp
將user_email
與舊的進行比較。user_email
通過email_exists()
到老。 wp_insert_user()
和user_url
, display_name
, nickname
, first_name
, last_name
, last_name
, description
,默認情況下:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.