Title: Random User Name
Last modified: August 22, 2016

---

# Random User Name

 *  Resolved [bryceholland](https://wordpress.org/support/users/bryceholland/)
 * (@bryceholland)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/)
 * Hi There,
 * I noticed you provided a filter for the older version of Profile Builder to have
   the user name be randomly generated if the user can register and login with an
   email address. It doesn’t look like the solution you provided before (here:[http://www.cozmoslabs.com/forums/topic/changing-the-pbuserxxxxxxxxxx-for-othe-random-function/](http://www.cozmoslabs.com/forums/topic/changing-the-pbuserxxxxxxxxxx-for-othe-random-function/))
   works for the new version of Profile Builder. Can you help me figure out how 
   to randomize the user name for the new version of PB if the user can login with
   email? I don’t want the user name to be the email address for privacy concerns.
   Thank you!
 * [https://wordpress.org/plugins/profile-builder/](https://wordpress.org/plugins/profile-builder/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [bryceholland](https://wordpress.org/support/users/bryceholland/)
 * (@bryceholland)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623207)
 * Hi There, Happy New Year! Any update on this thread? Thanks!
 *  Thread Starter [bryceholland](https://wordpress.org/support/users/bryceholland/)
 * (@bryceholland)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623269)
 * Hi There. I’m just wondering if there was a solution to this issue or if you 
   could help point me in the right direction here. Thank you!
 *  Plugin Author [adispiac](https://wordpress.org/support/users/adispiac/)
 * (@adispiac)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623272)
 * Hi Bryce,
    You’re right, in version 2 we’re generating the username based on 
   email. However, the same filter is available here: _wppb\_generated\_random\_username_.
 * So you can still use the code below to generate random usernames in case Login
   with Email is enabled.
 *     ```
       add_filter('wppb_generated_random_username', 'wppbc_rand_username', 10, 2);
       function wppbc_rand_username( $username, $user_email ){
           $username = wppbc_rand_based_on_charset();
           while ( username_exists( $username ) ){
               $username = wppbc_rand_based_on_charset();
           }
   
           return $username;
       }
       function wppbc_rand_based_on_charset(){
           $characters = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
           $length = strlen( $characters ) - 1;
           $result = '';
           for ($i = 0; $i < 8; $i++)
               $result .= $characters[mt_rand(0, $length)];
   
           return $result;
       }
       ```
   
 * Place this in an empty plugin or your theme’s functions.php file.
    I’ve tested
   it and it works as expected. Can you confirm?
 *  Thread Starter [bryceholland](https://wordpress.org/support/users/bryceholland/)
 * (@bryceholland)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623273)
 * Thank you very much! This works. I appreciate your help.
 *  Plugin Author [adispiac](https://wordpress.org/support/users/adispiac/)
 * (@adispiac)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623276)
 * Glad it works Bryce! You can always support our work by [leaving a review](https://wordpress.org/support/view/plugin-reviews/profile-builder?filter=5).

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Random User Name’ is closed to new replies.

 * ![](https://ps.w.org/profile-builder/assets/icon-256x256.png?rev=2961144)
 * [User Profile Builder - Beautiful User Registration Forms, User Profiles & User Role Editor](https://wordpress.org/plugins/profile-builder/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/profile-builder/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/profile-builder/)
 * [Active Topics](https://wordpress.org/support/plugin/profile-builder/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/profile-builder/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/profile-builder/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [adispiac](https://wordpress.org/support/users/adispiac/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/random-user-name/#post-5623276)
 * Status: resolved