There's a lot of discussions floating around the internet about md5 having been cracked, and sha1 as well. So far, the best way I've found to encrypt passwords is using a salt, which is a 32 character encryption key, containing lower-case, upper-case and numbers. (no symbols) Then hash the password using SHA1 with the defined encryption key(NOTE: SHA1 will create a 40 character string, where md5 creates a 32 character string, make sure the password field in your database is varchar(40))
For added security in your PHP applications, try creating a config file (for this example we'll name it encrypt.config.php) with the salt value like:
Code: Select all
$encrpyt = 'aEbahfga4651nsghay63521k78dGa4h';
Remember, the salt value needs to be 32 characters long.
Okay now we can include it in a helper file, let's call it encrypt.helper.php:
Code: Select all
function encrypt_with_salt($str)
{
include 'encrypt.config.php';
return sha1($str.$encrypt);
}
I'm using this code slightly differently in my application, but this generic example can be easily modified to suit your needs!
