All the examples online show the use of crypt like this:
$pass = crypt('something','$6$rounds=5000$anexamplestringforsalt$');
But everyone says that you are not supposed to define the rounds or the salt.
So how should I use it?
Also I am having a problem: when I run the code above, it only runs 50 rounds instead of 5000 rounds as if the system is stopping it.
Any help will be greatly appreciated.
//- Solution -//
I have found some of these to be useful:
For generating Salt:
Here is a random way of generating salt
$randomString = random_bytes(32);
Base 64 encode to ensure that some characters will not cause problems for crypt
$salt = base64_encode($randomString);
For Hashing:
$hashed = crypt($passwordInput, '$6$'.$salt);
To Confirm:
if (crypt($passwordInput, $hashed) == $hashed) {
// Valid action
} else {
// Invalid action
}
** Special Thanks to @lathspell for help with arriving at above solution **
str_shuffle
because it has max 32 bits of entropy and likely less (becausestr_shuffle
is not cryptagraphically secure) – Warden