Log in

View Full Version : [solved] How to Generate password hash+salt to new user


omardealo
06-07-2014, 04:38 PM
Hello ,

i make plug to add new user , user can register Directly from a link like this
misc.php?do=register&username=mark&email=mark@yahoo.com&password=67309

i get info from link and insert them on user table , No problem
My problem only , how i Generate the pass-hash and Generate salt ?!

i found this function on includes/functions_user.php

function fetch_user_salt($length = 3)
{
$salt = '';
for ($i = 0; $i < $length; $i++)
{
$salt .= chr(vbrand(33, 126));
}
return $salt;
}

it that Generate the salt ? and how can i used it ?

--------------- Added 1402164924 at 1402164924 ---------------

Thanks ... I found the solution and works well


// get password from link
$pass = $pass = $_GET['password'];

// Generate salt
function createSalt() {
$salt = '';
for ($i = 0; $i < 30; $i++) {
$salt .= chr(rand(33, 126));
}
return $salt;
}

//Generate password hash
function createPassword($password, $salt) {
return md5(md5($password) . $salt);
}

// Now you can store salt and password in your database .
$salt = createSalt();
$password = createPassword($pass, $salt);