How would it be possible to generate a random, unique string using numbers and letters for use in a verify link? Like when you create an account on a website, and it sends y
Simplifying Scotts code above by removing unnecessary loops which is slowing down badly and does not make it any more secure than calling openssl_random_pseudo_bytes just once
function crypto_rand_secure($min, $max)
{
$range = $max - $min;
if ($range < 1) return $min; // not so random...
$log = ceil(log($range, 2));
$bytes = (int) ($log / 8) + 1; // length in bytes
$rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
return $min + $rnd%$range;
}
function getToken($length)
{
return bin2hex(openssl_random_pseudo_bytes($length)
}