First commit
This commit is contained in:
20
bootstrap/helpers.php
Normal file
20
bootstrap/helpers.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Create cryptographically secure tokens of custom length
|
||||
*
|
||||
* @author Scott https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string/13733588#13733588
|
||||
*/
|
||||
function getToken($length){
|
||||
$token = "";
|
||||
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
|
||||
$codeAlphabet.= "0123456789";
|
||||
$max = strlen($codeAlphabet);
|
||||
|
||||
for ($i=0; $i < $length; $i++) {
|
||||
$token .= $codeAlphabet[random_int(0, $max-1)];
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
Reference in New Issue
Block a user