Building an Automatic Salt Generator
A Tutorial by ShanePerreault
Importance of Salting
To start things off, if you don't know what salting is, allow me to explain it to you.
$salt = "a%I:_"; $encrypted_password = md5(md5($salt) . md5($_POST['password']));
Now that password is safe from any Rainbow tables damage. Why? Because Rainbow Tables would have to get enormously gargantuan, even impossibly big, to be able to have a md5 string like the one above. Salting your encryptions is probably the easiest but most beneficial way to easily secure your website. So, now that we have a need for a salt, how do we get one.
Well, another leak i that if you're using the same salt string for every encryption, if someone looked at your code, they could most likely reverse engineer it to find the original password hash string. Which we don't want. So, we need to add one more column to our users table in our database called "salt", because every user's salt is going to be different. Here's what I use to generate random salts. It's randomized and shuffled around. And it gets the best salt strings anywhere.
public function generate_salt(){
$numbers = array("0","1","2","3","4","5","6","7","8","9");
$lcchars = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
$ucchars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$symbols = array('!','@','#','$','%','^','&','*','(',')','-','~','+','=','|','/','{','}',':',';',',','.','?','<','>','[');
$fake_salt = $numbers[array_rand($numbers)] . $lcchars[array_rand($lcchars)] . $ucchars[array_rand($ucchars)] . $symbols[array_rand($symbols)] . $symbols[array_rand($symbols)];
$salt = str_shuffle($fake_salt);
return $salt;
}The keyword public is in there because this method is from my Users class for registration and logging in. I hope that this is beneficial to you and your users. Keep your applications secure, because there ARE people who are going to try to break your software and hurt your users. I guarantee it. Salt away.
-Happy Coding






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None


















Help