I am using simple md5($password);
format but i want to add salt so how i can do that?
here is my code :
if($success)
{
$data['firstname'] = $firstname;
$data['lastname'] = $lastname;
$data['username'] = $username;
$data['password'] = md5($password);
$data['email'] = $email;
$newUser = new User($data);
$newUser->save(true);
$Newuser->login($username, $password);
header("Location: welcome.php");
}
$data['hashedpwd'] = md5($salt . $password);
The longer, more complex and unique to each user you can make the salt the harder it will be for anyone to get the password (though it's not impossible).
A simple (but poor salt) would be: $salt = '10';
A much stronger salt would be: $salt = '-45dfeHK/__yu349@-/klF21-1_\/4JkUP/4';
Salts that are unique to the user are even better.
As mentioned in several comments md5 is an old and relatively poor hashing algorythm, SHA-512 or any of the SHA-2 family would be much better choices.
See this salting question for more detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With