Wordpress 4 invalid username special charachters 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?

Topic htmlspecialchars-decode wp-login-form php login Wordpress

Category Web


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);

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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.