admin管理员组

文章数量:1287514

I have some danish users that uses special chars like æøå and they can't log in to my wordpress blog. I tried on a fresh install on 4.2.2 and on 4.1.5 and it did not work, for example Andrew Schønnemann with a simple password and it did not work, got message ERROR: Invalid username. Lost your password?. But with user Andrew Schonnemann works fine, what could be the issue?

I have some danish users that uses special chars like æøå and they can't log in to my wordpress blog. I tried on a fresh install on 4.2.2 and on 4.1.5 and it did not work, for example Andrew Schønnemann with a simple password and it did not work, got message ERROR: Invalid username. Lost your password?. But with user Andrew Schonnemann works fine, what could be the issue?

Share Improve this question asked May 22, 2015 at 15:56 AdrianAdrian 1131 silver badge8 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Are you creating your users via regular means or somehow importing them?

Trying to create such user WP prevents me from doing so:

ERROR: This username is invalid because it uses illegal characters. Please enter a valid username.

The reason for that is that username is validated with validate_username(), which runs sanitize_user() in strict mode. That reduces available characters to basic ASCII set.

In a nutshell WP doesn't consider that a valid username.

So the question is — is that actually a username in your case? Your users might be confusing Username with First/Last name fields, which are not used for login.

If you do want to support usernames like that you will have to override WP validation via hooks. That would probably take some serious testing to make sure it works properly and doesn't introduce security issues.

Found the answer, created the following function:

function wscu_sanitize_user ($username, $raw_username, $strict) {
    $username = wp_strip_all_tags ($raw_username);
    return $username;
}
add_filter ('sanitize_user', 'wscu_sanitize_user', 10, 3);

本文标签: phpWordpress 4 invalid username special charachters issue