Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    May 2010
    Posts
    5

    Default Unique Account Usernames

    Hi All,

    What methods do people use for guaranteeing the creation of a unique account username when using a createacct API call. I know in reality its possible to check the statusmsg for an error and respond to this with another API call if the account has failed on the account username not being unique but this seems like far too much effort. Really not sure why either the account username isnt just created dynamically as a unique username or why there isnt an API call to get a unique account username (unless there is and i've missed it somehow).

    Thanks

  2. #2
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Sep 2006
    Location
    Virginia Beach, VA
    Posts
    254
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    generally when you reach the point that you're worried about duplicate usernames, you have a more sophisticated method of assigning them. For instance, whatever billing or customer interface you're using will assign a username based on the domain, and if that username already exists, a new username is assigned. In other words, the billing system assigns the username before the API call to WHM is used.

  3. #3
    Member
    Join Date
    May 2010
    Posts
    5

    Default

    I'm not sure i agree with you to be honest. I can't really think of a use-case where an external username would want to be used within cPanel/WHM. Combined with that is the fact that WHM itself expects the admin user to determine that the username is unique when adding an account, this doesnt seem very elegant to me at all. Its very commonplace now in signup forms to have something along the lines of "check availability" for usernames. It would seem very useful to make this possible within WHM and then publish this element of the API.

  4. #4
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    Hi Seengee,

    I see your point: Such a mechanism would be feature request. You're welcome to post your idea in the Feature Request forum.

    I think there's some validity to what Vanessa is saying, though. For instance: if you had many, many WHM/cPanel boxes you'd probably used a centralized billing system for all the servers, otherwise keeping track of accounts on each server would be an overwhelming task. And depending on your desire or the billing software, it may be a requirement in the workflow that all your accounts had unique username across the entirety of your farm, not just any given server. It only makes sense then to use the billing system to automate account creation and management. In that scenario, you billing system would have the logic to keep track of account details; enough so to answer a 'check availability' type question. The billing system would use the APIs to perform CRUD as necessary on the server farm.

    -OR- you could roll the feature yourself with some:
    If you had only a handful of servers, you could make a script that aggregates a username list. I say only a handful cause this solution my not scale well, depending on your particular implementation.

    You'd use the XML-API, the function 'listaccts'.

    The query URL is simple:
    Code:
    https://10.1.1.1:2087/xml-api/listaccts
    it would generate a response something like:
    Code:
    <listaccts>
      <acct>
        <disklimit>unlimited</disklimit>
        <diskused>0M</diskused>
        <domain>dave.com</domain>
        <email>dave@test.test</email>
        <ip>192.168.99.190</ip>
        <maxaddons>*unknown*</maxaddons>
        <maxftp>unlimited</maxftp>
        <maxlst>unlimited</maxlst>
        <maxparked>*unknown*</maxparked>
        <maxpop>unlimited</maxpop>
        <maxsql>unlimited</maxsql>
        <maxsub>unlimited</maxsub>
        <owner>root</owner>
        <partition>home</partition>
        <plan>default</plan>
        <shell>/bin/bash</shell>
        <startdate>10 Aug 10 15:03</startdate>
        <suspended>0</suspended>
        <suspendreason>not suspended</suspendreason>
        <suspendtime></suspendtime>
        <theme>x3</theme>
        <unix_startdate>1281470609</unix_startdate>
        <user>dave</user>
      </acct>
    </listaccts>
    If you use the XML-API PHP client class, you code would look like this, only you'd have to loop/aggregate the results for the master list of what is not available.
    Code:
    include("xmlapi.php");
    
    $ip = "10.1.1.1";
    $root_user = "root";
    $root_pass = "r00ts3cr3t!";
    
    $xmlapi = new xmlapi($ip);
    
    $xmlapi->password_auth($root_user, $root_pass);
    
    $accounts = $xmlapi->listaccts();
    
    // do something with the $accounts object....
    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  5. #5
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Sep 2006
    Location
    Virginia Beach, VA
    Posts
    254
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by seengee View Post
    I'm not sure i agree with you to be honest. I can't really think of a use-case where an external username would want to be used within cPanel/WHM. Combined with that is the fact that WHM itself expects the admin user to determine that the username is unique when adding an account, this doesnt seem very elegant to me at all. Its very commonplace now in signup forms to have something along the lines of "check availability" for usernames. It would seem very useful to make this possible within WHM and then publish this element of the API.
    This is actually what a lot of hosting providers do - so *they* pick the usernames, instead of cPanel. When it gets to the point where you're managing more than one server, you can't guarantee that one server isn't going to pick a username that already exists on another.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    2

    Default PHP code to select unique username

    Hi. You may be interested - this PHP code I have developed for my own needs and it's well tested over 4000 calls. 2 methods do everything:

    Private Paste - Pastie

Similar Threads & Tags
Similar threads

  1. Replies: 4
    Last Post: 05-15-2009, 06:11 PM
  2. List all account usernames ?
    By fedlerner in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 12-25-2008, 01:01 PM
  3. apache unique ip
    By arkain in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 01-24-2007, 02:25 PM
  4. Webalizer unique visitors are different from awstat unique vistors
    By BianchiDude in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-09-2006, 05:00 AM
  5. mail account usernames
    By pug306d in forum New User Questions
    Replies: 1
    Last Post: 03-13-2005, 03:14 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube