Exemple #1
0
function get_token($length)
{
    $token = '';
    $codeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $codeAlphabet .= 'abcdefghijklmnopqrstuvwxyz';
    $codeAlphabet .= '0123456789';
    for ($i = 0; $i < $length; $i++) {
        $token .= $codeAlphabet[crypto_rand_secure(0, strlen($codeAlphabet))];
    }
    return $token;
}
Exemple #2
0
function getToken($length)
{
    $token = "";
    $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeAlphabet .= "abcdefghijklmnopqrstuvwxyz";
    $codeAlphabet .= "0123456789";
    for ($i = 0; $i < $length; $i++) {
        $token .= $codeAlphabet[crypto_rand_secure(0, strlen($codeAlphabet))];
    }
    return $token;
}
Exemple #3
0
function generateID($length)
{
    $id = "";
    $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeAlphabet .= "abcdefghijklmnopqrstuvwxyz";
    $codeAlphabet .= "0123456789";
    $max = strlen($codeAlphabet) - 1;
    for ($i = 0; $i < $length; $i++) {
        $id .= $codeAlphabet[crypto_rand_secure(0, $max)];
    }
    return $id;
}
/**
* Credit: Scott - http://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string/13733588#13733588
*/
function getToken($length)
{
    $securityToken = "";
    $codeSource = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeSource .= "abcdefghijklmnopqrstuvwxyz";
    $codeSource .= "012345678901234567890123456789";
    // assign token farm length to $max
    $max = strlen($codeSource) - 1;
    for ($i = 0; $i < $length; $i++) {
        $securityToken .= $codeSource[crypto_rand_secure(0, $max)];
    }
    return $securityToken;
}
 /**
  * selects questions randomly in the question list
  *
  * @author - Olivier Brouckaert
  * @return - array - if the exercise is not set to take questions randomly, returns the question list
  * 					 without randomizing, otherwise, returns the list with questions selected randomly
  */
 function selectRandomList()
 {
     // if the exercise is not a random exercise, or if there are not at least 2 questions
     if (!$this->random || $this->selectNbrQuestions() < 2 || $this->random <= 0) {
         return $this->questionList;
     }
     // takes all questions
     if ($this->random > $this->selectNbrQuestions()) {
         $draws = $this->selectNbrQuestions();
     } else {
         $draws = $this->random;
     }
     $randQuestionList = array();
     $alreadyChosed = array();
     // loop for the number of draws
     for ($i = 0; $i < $draws; $i++) {
         // selects a question randomly
         do {
             $rand = crypto_rand_secure(0, $this->selectNbrQuestions() - 1);
         } while (in_array($rand, $alreadyChosed));
         $alreadyChosed[] = $rand;
         $j = 0;
         foreach ($this->questionList as $key => $val) {
             // if we have found the question chosed above
             if ($j == $rand) {
                 $randQuestionList[$key] = $val;
                 break;
             }
             $j++;
         }
     }
     return $randQuestionList;
 }
Exemple #6
0
/**
 * Function for generating fixed-length strings containing random characters.
 *
 * @param int $length
 * @return string
 */
function randomkeys($length)
{
    $key = "";
    $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeAlphabet .= "abcdefghijklmnopqrstuvwxyz";
    $codeAlphabet .= "0123456789";
    for ($i = 0; $i < $length; $i++) {
        $key .= $codeAlphabet[crypto_rand_secure(0, strlen($codeAlphabet) - 1)];
    }
    return $key;
}
function getToken($length)
{
    //echo "first step";
    $token = "";
    $codeAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeAlpha .= "abcdefghijklmnopqrstuvwxyz";
    $codeAlpha .= "0123456789";
    // echo "before max";
    $max = strlen($codeAlpha) - 1;
    for ($i = 0; $i < $length; $i++) {
        $token .= $codeAlpha[crypto_rand_secure(0, $max)];
    }
    return $token;
}
Exemple #8
0
function create_pass()
{
    $parts = array('a', 'ba', 'fa', 'ga', 'ka', 'la', 'ma', 'xa', 'e', 'be', 'fe', 'ge', 'ke', 'le', 'me', 'xe', 'i', 'bi', 'fi', 'gi', 'ki', 'li', 'mi', 'xi', 'o', 'bo', 'fo', 'go', 'ko', 'lo', 'mo', 'xo', 'u', 'bu', 'fu', 'gu', 'ku', 'lu', 'mu', 'xu', 'ru', 'bur', 'fur', 'gur', 'kur', 'lur', 'mur', 'sy', 'zy', 'gy', 'ky', 'tri', 'kro', 'pra');
    $max = count($parts) - 1;
    $num = crypto_rand_secure(10, 499);
    return $parts[crypto_rand_secure(0, $max)] . $parts[crypto_rand_secure(0, $max)] . $num;
}