[wp-trac] [WordPress Trac] #59084: Spaces in username during login

WordPress Trac noreply at wordpress.org
Sat Aug 12 06:56:50 UTC 2023


#59084: Spaces in username during login
-------------------------------------------+-----------------------------
 Reporter:  wparslan                       |      Owner:  (none)
     Type:  defect (bug)                   |     Status:  new
 Priority:  normal                         |  Milestone:  Awaiting Review
Component:  General                        |    Version:  trunk
 Severity:  normal                         |   Keywords:
  Focuses:  accessibility, sustainability  |
-------------------------------------------+-----------------------------
 The username can have spaces in them which is not a good practice of
 usernames.
 Yes, during the registration it escapes and converts the space to %20 for
 the username.

 We can restrict the user to more efficient username with this:
 {{{#!php
 <?php

 /**
  * Check if the sanitized username contains spaces and add an error if
 needed.
  *
  * This function is hooked into the registration_errors filter to check
 the sanitized
  * username for spaces. If a space is found in the username, an error
 message is added
  * to the list of registration errors.
  *
  * @param WP_Error $errors            A WP_Error object containing any
 registration errors.
  * @param string   $sanitized_user_login The sanitized username without
 spaces or special characters.
  * @param string   $user_email        The email address entered during
 registration.
  * @return WP_Error Modified WP_Error object with added error message, if
 applicable.
  */
 function loginpress_check_username_for_spaces( $errors,
 $sanitized_user_login, $user_email ) {
     if ( strpos( $sanitized_user_login, ' ' ) !== false ) {
         $errors->add( 'username_space', __( 'Username cannot contain
 spaces.', 'text-domain' ) );
     }
     return $errors;
 }
 add_filter( 'registration_errors', 'prefix_check_username_for_spaces', 10,
 3 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59084>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list