shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

general.php (854B)


      1 <?php
      2 function token($length = 32) {
      3 	// Create random token
      4 	$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      5 	
      6 	$max = strlen($string) - 1;
      7 	
      8 	$token = '';
      9 	
     10 	for ($i = 0; $i < $length; $i++) {
     11 		$token .= $string[mt_rand(0, $max)];
     12 	}	
     13 	
     14 	return $token;
     15 }
     16 
     17 /**
     18  * Backwards support for timing safe hash string comparisons
     19  * 
     20  * http://php.net/manual/en/function.hash-equals.php
     21  */
     22 
     23 if(!function_exists('hash_equals')) {
     24 	function hash_equals($known_string, $user_string) {
     25 		$known_string = (string)$known_string;
     26 		$user_string = (string)$user_string;
     27 
     28 		if(strlen($known_string) != strlen($user_string)) {
     29 			return false;
     30 		} else {
     31 			$res = $known_string ^ $user_string;
     32 			$ret = 0;
     33 
     34 			for($i = strlen($res) - 1; $i >= 0; $i--) $ret |= ord($res[$i]);
     35 
     36 			return !$ret;
     37 		}
     38 	}
     39 }