WooCommerce:如何降低註冊帳號時的密碼強度

更新日期:2023-08-25
讓我的客戶網站GTmetrix測分A\A的主機Cloudways
獨家優惠

註冊時填寫優惠碼LOYSEO

享前3個月7折

免去實名認證
自動帶入優惠
免費試用3 天
可領獨家福利
獨家福利

三選一

相關架設網站教學

在使用WooCommerce製作電商獨立站時,如果你設定的是允許客戶註冊時填寫密碼,那麼,在填寫密碼時,會要求客戶使用強密碼,要求是12位的字元串,得有字母、數位、特殊字元。 如果覺得這個要求太嚴苛,可以通過以下的代碼段來降低註冊帳號時的密碼強度要求。

首先,請安裝Code Snippet外掛

然後,添加一個新的snippet,代碼類型是function(php),將下方代碼複製進去,保存即可。

這段代碼,實現了:註冊要求最低9個字元,純字母和數字的組合也是允許的。

// First, change the required password strength
add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
    // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
    return 1;
}

// Second, change the wording of the password hint.
add_filter( 'password_hint', 'smarter_password_hint' );
function smarter_password_hint ( $hint ) {
    $hint = 'Hint: The password should be at least nine characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).';
    return $hint;
}    

代碼中的,我們能看到一段, 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).,這是一段註釋,告訴你密碼強度分為0-3,共計4個等級,數值越大,密碼要求越強。 默認是3,我們將return 1中的1改為你需要的數值,即可調整強度。

在code snippet外掛程式中加完的代碼,長下圖這樣。

WooCommerce:如何降低註冊帳號時的密碼強度

点赞

0 / 5 0

Your page rank:

Picture of 外貿建站技術姐Bonnie
外貿建站技術姐Bonnie

Bonnie是LOYSEO的創始人,在架設網站領域有著超過15年的經驗,熱愛能將想法變為現實的WordPress,更是Elementor的忠實使用者~