I'm trying to write a secure code that can keep my site users passwords as safe as possible. Now I'm fairly new to encryption and would like some professional opinions and suggestions. As well as a raw estimate of how long it would take to brute force my current encryption method.
So my encryption begins with creating a random SALT value as such
$salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647));
After the SALT value is create it is hashed using SHA-256 as such
$password = hash('sha256', $_POST['bindPass'] . $salt);
After the $password hash is create I re-hash the values to secure them farther
for($round = 0; $round < 656757; $round++)
{
$password = hash('sha256', $password . $salt);
}
Now after rehashing is done the Encryption is bound to a function and is added directly into PDO Insert query. Here is the Encryption function.
function encrypt_cpass($in)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_TWOFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$enc = mcrypt_encrypt(MCRYPT_TWOFISH,ENCRYPT_KEY, $in, MCRYPT_MODE_ECB, $iv);
$enc = base64_encode($enc);
return $enc;
}
And finally the PDO part
$query_params = array(
':password' => encrypt_cpass($password),
..........
}
I can't say I get bad performance with the following code and the script, but I am more worried that I may be doing the password securing not the right way and it may eventually be broken. So again if you have any suggestions or could point me to some good resources please post them.
Cheers.
mt_rand
is a very bad source of randomness. Don't invent your own mechanism; use bcrypt, stackoverflow.com/questions/4795385/…