The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Username Exists

Discussion in 'cPanel Developers' started by Bytescanada, Apr 21, 2009.

  1. Bytescanada

    Bytescanada Member

    Joined:
    Aug 31, 2002
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    I am slowly converting over my hosting script to use cpanels xmlapi, but I was wondering if it is possible when somebody signs up they are able to check if a username exists. I have been searching for hours with little luck. Might not be seaching for the right thing. Anybody have any ideas or guidance that can be provided.

    Thanks
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    One way you can do this is search for that user's username using the listaccts function. There's some documentation on how to do this at:

    http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/ListAccounts

    Alternatively, you could attempt to create the account and when an error comes back indicating the username already exists, prompt your customer for a different username and try again.
     
  3. Bytescanada

    Bytescanada Member

    Joined:
    Aug 31, 2002
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    k, thanks cPanelDavidG. Now just to learn Javascript or Ajax to have this work the way I need it to and figure how out to output the xml code.
     
  4. stoo2000

    stoo2000 Active Member

    Joined:
    Jul 26, 2003
    Messages:
    43
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Leicestershire, UK
    cPanel Access Level:
    Root Administrator
    This (PHP) function cycles through the existing usernames and comes up with the next unique one, built from the customers first name and surname.

    It returns the username once it's found one.

    Code:
    function workout_user($fname, $sname)
    	{
    		$fname = substr($fname, 0, 4);
    		$lim = 9 - strlen($fname);
    		for($i = 0; $i <= $lim; $i++ )
    		{
    			if (array_key_exists('user', $this->list_accounts('user', $fname . substr($sname, 0, $i))->acct))
    			{
    				continue;
    			}
    			else
    			{
    				return strtolower($fname .  substr($sname, 0, $i));
    				break;
    			}
    		}
    	}
    $this->list_accounts is the result of... '/xml-api/listaccts?searchtype=$arg1&search=$arg2' - $argx are from the function call above. (passed thru simplexml_load_string(); )
     
    #4 stoo2000, Apr 25, 2009
    Last edited: Apr 25, 2009
Loading...

Share This Page