This should help:
http://xenforo.com/community/threads/password-formula.32191/#post-367845
sha1(sha1(password) . salt)
or:
sha256(sha256(password) . salt)
You've tried both and they didn't work?
They are the only methods used by XenForo to hash passwords. The method used depends on whether you have the relevant PHP extension installed.
Are you using the salt also? Are you making sure you hash the password then re-hash it with the salt?No. They didn't work.
When I used SHA1, the result was not the same as the one in the database.
When I used SHA256, it resulted in error.
I used:Are you using the salt also? Are you making sure you hash the password then re-hash it with the salt?
They're running on the same server.What was the error?
Is the PHP script and XenForo install running on the same server? If not, it's possible that your server running the PHP script doesn't have the correct PHP extension installed whereas your XenForo install does.
Yep, that's correct. I'm not sure why it wouldn't return the same string unless something is wrong in the password and/or salt.I used:
sha1(sha1($password) . salt)
Was this correct?
They're running on the same server.
The error was an Internal error. Seemed like the server could not define SHA256. So, the stored passwords should be SHA1-encrypted, shouldn't they?
Still doesn't work.Yep, that's correct. I'm not sure why it wouldn't return the same string unless something is wrong in the password and/or salt.
You should create a test account, grab the hash from the database, grab the salt and create a script to see if the hash is correct.
Thanks for your support.We'd probably need to see your code to be able to debug it effectively.
At the moment we can only see one half of the equation, e.g. the actual formula XenForo uses. The part we can't see, e.g. your script might be the part that leads us to the solution.
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$password = sha1(sha1($password) . salt);
$con = mysql_connect("localhost","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mcsmilew_forum",$con);
$idsearch = mysql_query("SELECT user_id FROM xf_user WHERE username = '$username'");
while ($row = mysql_fetch_assoc($idsearch)) {
$user_id = $row['user_id'];
$authenticate = mysql_query("SELECT remember_key FROM xf_user_authenticate WHERE user_id = '$user_id'");
while ($row = mysql_fetch_assoc($authenticate)) {
$forumpassword = $row['remember_key'];
}
if($password == $forumpassword){
echo "Password Correct";
}
else{
echo "Password Incorrect<br>";
}
}
?>
<?php
$startTime = microtime(true);
$fileDir = dirname(__FILE__);
require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);
$username = 'Kier';
$password = 'KiersPassword';
$db = XenForo_Application::getDb();
$data = $db->fetchOne('
SELECT
auth.data
FROM xf_user_authenticate AS auth
INNER JOIN xf_user AS user ON
(user.user_id = auth.user_id)
WHERE user.username = ?
', $username);
$auth = XenForo_Authentication_Abstract::createDefault();
$auth->setData($data);
$check = $auth->authenticate($username, $password);
Zend_Debug::dump($check);
Many Thanks!I'm relatively new to PHP also, and the only PHP experience I have is ALL XenForo.
I've just figured out this little script that may help...
Because I always think in XenForo, I literally do nothing unless it involves XenForo. So the following does what you want, but entirely using XenForo functions and classes. You should be able to call these from your script.
PHP:<?php $startTime = microtime(true); $fileDir = dirname(__FILE__); require($fileDir . '/library/XenForo/Autoloader.php'); XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library'); XenForo_Application::initialize($fileDir . '/library', $fileDir); XenForo_Application::set('page_start_time', $startTime); $username = 'Kier'; $password = 'KiersPassword'; $db = XenForo_Application::getDb(); $data = $db->fetchOne(' SELECT auth.data FROM xf_user_authenticate AS auth INNER JOIN xf_user AS user ON (user.user_id = auth.user_id) WHERE user.username = ? ', $username); $auth = XenForo_Authentication_Abstract::createDefault(); $auth->setData($data); $check = $auth->authenticate($username, $password); Zend_Debug::dump($check);
So, talking through it.
The first 10 lines (before $username) basically load XenForo's classes.
You need to specify the full server path to Autoloader.php, in my case my PasswordCheck.php is in the XenForo root so the __FILE__ parameter is sufficient.
I then set the username and password (obviously this can be retrieved from $_POST parameters instead).
I then get the database. This handles all of the database authentication and everything.
Big difference between my code and your code is I'm selecting 'data' from xf_user_authenticate NOT the remember_key. I'm not sure what the remember_key is, but it's something different. I believe data essentially contains your password hash and salt amongst other things in a serialised array.
Now I've got that, I create the default XenForo authentication object and set the data I retrieved from the database.
I can then make a call to the authenticate function and pass in my username and password.
The response will either be true or false. I have dumped the response using Zend_Debug::dump($check)
$auth creates the authentication handler.Many Thanks!
Does $auth stand for the result (true or false), right?
For Zend_Debug, you need Zend Framework to use this, right?$auth creates the authentication handler.
In my code it's:
$check = $auth->authenticate($username, $password);
That contains the result of the check. Will either be true or false.
Thank you very much.It's built into XenForo and loaded along with the XenForo Autoloader.
For testing purposes you could equally just use something like:
PHP:if ($check) { echo 'success'; } else { echo 'fail'; }
I got an error: HTTP500 Internal Error.It's built into XenForo and loaded along with the XenForo Autoloader.
For testing purposes you could equally just use something like:
PHP:if ($check) { echo 'success'; } else { echo 'fail'; }
We use essential cookies to make this site work, and optional cookies to enhance your experience.