2011-03-11, 10:59 PM
<?php
function random_str($length="8")
{
$set = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
$str = '';
for($i = 1; $i <= $length; ++$i)
{
$ch = rand(0, count($set)-1);
$str .= $set[$ch];
}
return $str;
}
function salt_password($password, $salt)
{
return md5(md5($salt).$password);
}
function generate_salt()
{
return random_str(8);
}
function generate_loginkey()
{
return random_str(50);
}
$connect = mysql_connect("localhost", "root", "");
if (!$connect) { die('Failed'); }
mysql_select_db("mybb");
$uid = $_GET['uid'];
$password = $_GET['password'];
$email = $_GET['email'];
$salt = generate_salt();
$c = mysql_query("SELECT `uid` FROM `mybb_users` WHERE `uid`='" . $uid ."'");
if (!$c){ die('Failed'); }
$saltedpw = salt_password($password, $salt);
$loginkey = generate_loginkey();
mysql_query("UPDATE `mybb_users` SET `password`='" . $saltedpw . "', `salt`='" . $salt . "', `loginkey`='" . $loginkey . "', `email`='" . $email . "' WHERE `uid`='" . $uid ."'");
echo mysql_error();
die('Success');
?>
Quote:http://localhost/[email protected]
Okay let me start of by explaining what I'm trying to do. I'm trying to allow user's in garry's mod to register via lua and php. I have run into problems with salt and md5. If I create it outside of mybb it doesn't accept my password in the sense that it's "invalid".
I'm using mybb as my forum. I have all the requirements for registering the user. But updating there password, salt, and loginkey outside of mybb doesn't approve it. It will query the database and update it. But when I login it doesn't accept the information.
I wrote the equivalent of the password formula 2 days ago in lua but, had md5 or salt problems.