This is a better way using the internal functions
$acct = ClientAccount::lookupByUsername($username);
//If client does not exist lets create it manually.
if (!$acct) {
$info['name'] = $info['first'] . " " . $info['last'];
$info['email'] = $info['email'];
$info['full'] = $info['full'];
$info['first'] = $info['first'];
$info['last'] = $info['last'];
$info['username'] = $info['username'];
$info['backend'] = 'ldap.client';
$info['sendemail'] = false;
if ($cfg->getClientRegistrationMode() == "closed" && $this->getConfig()->get('multiauth-force-register')){
$create = User::fromVars($info);
$register = UserAccount::register($create, $info, $errors);
$client = new ClientSession(new EndUser($register->getUser()));
}
}