Jump to content

Admin User Password Hash Problems


adam.burst.net

Recommended Posts

I am attempting to use the Remote API functions to insert an invoice for a client. I have tried over and over again but am having problems getting the Admin user to authenticate properly.

 

when I run through the API call as specified by the API:Example_usage with:

$username = 'api_user';
$password = md5('api_pass');

 

I get authentication errors, but if I copy and paste the hash directly from the database like:

$username = 'api_user';
$password = '<DB_PASSWORD_FIELD_VALUE>';

 

the API call executes without a hitch.

 

I am curious as to why this is happening and what I can do in order to fix it.

Link to comment
Share on other sites

That is very odd. What does the md5 hash output? Is it generating the same hash that's in your database?

 

If I were you I would just put the hash from the database directly into the code anyways. This is because if anyone ever gets their hands on this code of yours they only have a hash and not your password and the hash. Seems simply more secure to me :)

Link to comment
Share on other sites

That is true, but the API user only has API access. So it wouldn't really matter if they got the hash or the password, they could still only use the API. They would never be able to log in.

 

When using the md5() function in PHP, or the md5_hex() function in PERL, it always outputs a 32 character [0-9a-f] string. That string does not match the string stored in the tbladmins.password field. I have no idea why, but its been driving me nuts for a while now.

 

Unfortunately, storing the Hash instead of the password is kind of a pain. I can't really get into details, but it is due to some oversights by a previous employee.

Link to comment
Share on other sites

EUREKA!

 

I have been at this for hours now trying to figure this thing out, and it is due to a problem with special characters.

 

The password that I am using for the API user contains an ampersand(&). When WHMCS creates the user via the admin interface, the & character is likely filtered through 'htmlentities()', and then the MD5 is created.

 

This means:

<?php
$password = 'abc&123';

$escaped_password = htmlentities($password);

echo md5($password); // Does not match database hash
echo md5($escaped_password); // Matches database hash

?>

 

This means that when I construct my API call and I encode the plaintext password 'abc&123' it will not work because the MD5 sum expected by WHMCS is based on the password 'abc&123'.

 

I would assume that this is a bug that would affect every other special character in passwords that wold be converted into HTML encoding.

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