Topic-icon Automatically crop username to firstname.initialoflastname

Active Subscriptions:

None
Hi,

I would like to change the default username generation so instead of first.lastname it defaults to first.initial so John Doe becomes John.D (ideally with capitalisation of the J and D. Could you possibly tell me what file to override, and with what code?

Very many thanks

David
The topic has been locked.
Support Specialist
David,
With that 'generic' of a username, you're going to get a lot of duplicates, which means there will be a lot of John.D, John.D123, John.D124, etc. Shouldn't cause any issues, just means there will be numbers.

To change it, edit the /libraries/sourcecoast/utilities.php file. Around line 470, you'll see:
else if ($email != '') //email
        {
            $prefix = $email;
        }

        if($prefix != '')
        {
            $suffix = SCUserUtilities::getUsernameUniqueNumber($prefix);
            return $prefix . $suffix;
        }
Add the following block in there, so it looks like:
else if ($email != '') //email
        {
            $prefix = $email;
        }

        // ADD THIS BLOCK
            $firstName = SCStringUtilities::strtolower($firstName);
            $lastName = SCStringUtilities::strtolower($lastName);

            $lastPrefix = SCStringUtilities::substr($lastName, 0, 1);
            $prefix = $firstName . $lastPrefix;
       // END NEW BLOCK

        if($prefix != '')
        {
            $suffix = SCUserUtilities::getUsernameUniqueNumber($prefix);
            return $prefix . $suffix;
        }
That's completely untested, so you (should) know the drill. Test, test, and test some more.. and let us know how it goes!

That change will need to be made any time you update JFBConnect. We may look into adding that as an option, but it won't be in the next release or anytime I can commit too.

Good luck,
Alex
The topic has been locked.