Skip to:

Auto Generate Username During Registration

  • ch1n3s3b0y



    I have adjusted my registration form to not display the username field. I only want users to be able to login with their email and so the username field is essentially redundant; however it is still required for WordPress/Buddypress.

    I have found script to autogenerate a random string which is fine. What I am having trouble with, is how do I intercept the registration, before it actually registers the user so that I can randomly generate the username? I don’t want to insert a randomly generated username into the form and simply hide it, as a savvy user could view the source and change the value of the username field.

    Also, is anyone aware of a simple way to check whether the username is available or not? I know that if I use a random string of 10 characters that it is unlikely that it will exist, but it is better to be safe rather than sorry.


Viewing 1 replies (of 1 total)

  • modemlooper


    Make the field hidden. It won’t matter as you can intercept the $_POST and override anything they add.

    This is a quick example.

    function bp_auto_generate_username(){
        $my_post = $_POST;
        $my_post['signup_username'] = 12345;
    add_action( 'bp_signup_pre_validate', 'bp_auto_generate_username' );
Viewing 1 replies (of 1 total)
  • The topic ‘Auto Generate Username During Registration’ is closed to new replies.
Skip to toolbar