Jump to content

Generate username from server module


Eduardo G.

Recommended Posts

Hi all. I've been working with a couple of server modules that create a user account in their respective servers.

These modules do not requiere the user to enter any domain information.

 

From inside _CreateAccount() method, I can read a random generate password from $params['password']

There's also a parameter with the username for this order ($params["username"]), but does not autogenerate (it uses to take domain name , but there is no domain name here)

 

Question is: how should I generate a username?

Should I create a customfield for the product where user can manually enter a username (same way as when client enters hostname for a server)?

Or should I generate a new username based on client's full name or company name?

 

Question is more logical thant technical, hope you can give me some ideas.

Thanks!

Link to comment
Share on other sites

Hi all. I've been working with a couple of server modules that create a user account in their respective servers.

These modules do not requiere the user to enter any domain information.

 

From inside _CreateAccount() method, I can read a random generate password from $params['password']

There's also a parameter with the username for this order ($params["username"]), but does not autogenerate (it uses to take domain name , but there is no domain name here)

 

Question is: how should I generate a username?

Should I create a customfield for the product where user can manually enter a username (same way as when client enters hostname for a server)?

Or should I generate a new username based on client's full name or company name?

 

Question is more logical thant technical, hope you can give me some ideas.

Thanks!

 

The username is generated when the create function is called. It defaults to the first 8 letters of the domain, but since you aren't using a domain name for this module, perhaps you need to create one randomly. You can turn on random usernames in the WHMCS config but that will affect all provisioning modules, not just yours.

 

This is a very basic and simple string generator!

function genRandomString() {
   $length = 10;
   $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
   $string = '';

   for ($p = 0; $p < $length; $p++) {
       $string .= $characters[mt_rand(0, strlen($characters))];
   }

   return $string;
}

Edited by tsiedsma
Link to comment
Share on other sites

Thanks, tsiedsma, but was not looking for a random username generator, as users would never remmember their own usernames as username cannot be changed later :-S

 

For the moment, I'll keep using a custom field called 'username' for the product, even if it makes necessary one more step to activate these server modules.

 

Best regards ;-)

Link to comment
Share on other sites

If you want the user to create their own username, that is possible but you'll have to make sure that there aren't any other users with the same username accessing that resource. You'll also have to clean the username of illegal characters and truncate it if necessary. I would create a custom fields for this and then process the data during module creation and update the tblhosting.username field with the proper username.

 

You could also create the username based on their firstname and lastname. There are many options!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated