Jump to content
  • 0

way to do external authentication


DaveR

Question

I'd like to use WHMCS as the billing system for our existing online service, but I'd rather not keep 2 sets of credentials.

 

What I need is a way to "hook" WHMCS' authentication and use our own code there.

 

What would happen is that when a user enters the username/password on a WHMCS page, rather than looking it up in WHMCS db, our custom code would perform the authentication check and return either a 'false', or return the WHMCS client id of the authenticated user.

 

Is there a way to do this with a hook or other modification?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

It would be easier to hook your existing system into the login for WHMCS, since you cannot directly modify the source for it. Its fairly simple to either test authentication using headers, or just use the API and do a "getclientpassword" API call. Something like this should work:

 

<?php
$email= $_POST['email'];
$password = md5($_POST['password']);

$whmcs_url = "https://yourdomain.com/whmcs/api.php";
$admin_uid = "admin";
$admin_pw = "password";

$data = select_query('tblclients', 'id', array('email'=>$email));
if (mysql_num_rows($data)) {
 $r = mysql_fetch_array($data);
 $userid = $r[0];
} else {
 print "Bad Email Address";
 exit(1);
}

$postfields["username"] = $admin_uid;
$postfields["password"] = md5($admin_pw);
$postfields["action"] = "getclientpassword";
$postfields["userid"] = $userid;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcs_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$cdata = curl_exec($ch);
curl_close($ch);
$cdata = explode(";",$cdata);
foreach ($data AS $temp) {
 $temp = explode("=",$temp);
 $results[$temp[0]] = $temp[1];
}
if ($results['password']=="$password")  {
 print "Password Good";
} else {
 print "Password Bad";
}

?>

 

Please note that this is completely untested and may not work at all.

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
Answer this question...

×   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