我们需要在wordpress站点中强制实施密码复杂性,我们使用了本文:
http://www.webtipblog.com/force-password-complexity-requirements-wordpress/
我们在函数中创建了以下内容。php:
add_action(\'user_profile_update_errors\', \'validateProfileUpdate\', 10, 3 );
add_filter(\'registration_errors\', \'validateRegistration\', 10, 3 );
add_action(\'validate_password_reset\', \'validatePasswordReset\', 10, 2 );
function validateProfileUpdate( WP_Error &$errors, $update, &$user ) {
return validateComplexPassword( $errors );
}
function validateRegistration( WP_Error &$errors, $sanitized_user_login, $user_email ) {
return validateComplexPassword( $errors );
}
function validatePasswordReset( WP_Error &$errors, $userData ) {
return validateComplexPassword( $errors );
}
function validateComplexPassword( $errors ) {
$password = ( isset( $_POST[ \'pass1\' ] ) && trim( $_POST[ \'pass1\' ] ) ) ? $_POST[ \'pass1\' ] : null;
if ( empty( $password ) || ( $errors->get_error_data( \'pass\' ) ) )
return $errors;
$passwordValidation = validatePassword($password);
if ( $passwordValidation !== true ) {
$errors->add( "pass", "<strong>ERROR</strong>: " . $passwordValidation . "." );
}
return $errors;
}
function validatePassword($Password) {
//#### Check it\'s greater than 6 Characters
if (strlen($Password) < 6) {
return "Password is too short (" . strlen($Password) . "), please use 6 characters or more.";
}
//#### Test password has uppercase and lowercase letters
if (preg_match("/^(?=.*[a-z])(?=.*[A-Z]).+$/", $Password) !== 1) {
return "Password does not contain a mix of uppercase & lowercase characters.";
}
//#### Test password has mix of letters and numbers
if (preg_match("/^((?=.*[a-z])|(?=.*[A-Z]))(?=.*\\d).+$/", $Password) !== 1) {
return "Password does not contain a mix of letters and numbers.";
}
//#### Password looks good
return true;
}
正如你所看到的,我们利用了
validate_password_reset
挂钩(&A);用它来称呼我们的定制
validatePassword()
使用两个简单正则表达式测试密码的函数。
然而,当用户通过重置密码时,似乎根本不会调用此代码wp-login.php
- 我们知道这一点,因为它仍然允许我们输入密码“woof”(这显然是无效的),并在validateComplexPassword()
函数向我们发送电子邮件,同样,没有激发任何电子邮件。
我们的代码有问题吗?是validate_password_reset
不再调用操作?帮助:)
Edit: 我们在php错误日志中注意到了以下内容-这可能是问题所在吗?
[12-Jun-2014 14:38:12 UTC] PHP Warning: Parameter 1 to mycohens_validatePasswordReset() expected to be a reference, value given in C:\\inetpub\\wwwroot\\www.cohenschemist.co.uk\\wp-includes\\plugin.php on line 470
Edit 2: 试图通过wp admin/profile更改密码。php工作得很好,wordpress返回了自定义代码中的错误,只是忘记了密码重置,似乎不起作用。