Remove Username Character Limit from WordPress Multi-Site / Multi-User

May 13th, 2010  |  Published in Mind

I’ve been working on a pretty complex project with WordPress MultiUser (soon to be MultiSite). This client needs several sites with hundreds of users divided into each site. I will be integrating the backend authentication with LDAP and discovered that a small percentage of their users have usernames with fewer than four characters.

WordPress MU currently has a minimum limit of four characters set in its core. Unfortunately, this limit is still imposed in WordPress MS 3.0. The limit is probably there because usernames were used for the domain too and WP-Devs didn’t want to conflict with country codes. But that is not an issue for my client, so I wanted to kill the limit (without touching core).

Basically, I wrote a quick mu-plugin that unset the error message when someone tries to add a user with fewer than four characters. Doing this removes any halts that would stop processing the new user. Here is my code:

function remove_username_char_limit($result) {
  if ( is_wp_error( $result[ 'errors' ] ) && !empty( $result[ 'errors' ]->errors ) ) {

    // Get all the error messages from $result
    $messages = $result['errors']->get_error_messages();
    $i = 0;
    foreach ( $messages as $message ) {

      // Check if any message is the char limit message
      if ( 0 == strcasecmp("Username must be at least 4 characters", $message)) {
        // Unset whole 'user_name' error array if only 1 message exists
        // and that message is the char limit error
        if ( 1 == count($messages) ) {
          unset( $result['errors']->errors['user_name'] );
        } else {
          // Otherwise just unset the char limit message
          unset( $result['errors']->errors['user_name'][$i] );
        }
      }	

      $i++;
    }
  }

  return $result;
}
add_action('wpmu_validate_user_signup', 'remove_username_char_limit');

Tags: , , , , , ,

Should Twitter Ban Users for using the ‘accept username’ Vulnerability?

May 10th, 2010  |  Published in Mind

Recently a Twitter vulnerability was leaked that allowed Twitter users to type ‘accept username‘ (where username was another twitter user) and it forced that user to follow you. For instance, the last time I looked Conan O’Brien’s account had over 300 followers. Even though he said he was only going to follow 1 random person (Sarah Killen @LovelyButton).

UPDATE: Twitter has responded to this vulnerability and is in the process of rolling back the invalid follows.

Tags: ,