php 用户验证 base64验证方法

四月 22, 2019 | views
Comments 0

  1. function dsetcookie($var$value$life = 0, $prefix = 1) { 
  2.  global $cookiedomain$cookiepath$addtime$_server
  3.  setcookie($var$value,$life ? $addtime + $life : 0, $cookiepath,$cookiedomain$_server['server_port'] == 443 ? 1 : 0); 
  4.  
  5. function authcode($string$operation = 'decode'$key = ''$expiry = 0) { 
  6.     global $webaddr
  7.     $auth_key=md5($webaddr); 
  8.  $ckey_length = 4; 
  9.  $key = md5($key ? $key : $auth_key); 
  10.  $keya = md5(substr($key, 0, 16)); 
  11.  $keyb = md5(substr($key, 16, 16)); 
  12.  $keyc = $ckey_length ? ($operation == 'decode' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : ''
  13.  $cryptkey = $keya.md5($keya.$keyc); 
  14.  $key_length = strlen($cryptkey); 
  15.  $string = $operation == 'decode' ? base64_decode(substr($string$ckey_length)) : sprintf('%010d'$expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string
  16.  $string_length = strlen($string); 
  17.  $result = ''
  18.  $box = range(0, 255); 
  19.  $rndkey = array(); 
  20.  for($i = 0; $i <= 255; $i++) { 
  21.   $rndkey[$i] = ord($cryptkey[$i % $key_length]); 
  22.  } 
  23.  for($j = $i = 0; $i < 256; $i++) { 
  24.   $j = ($j + $box[$i] + $rndkey[$i]) % 256; 
  25.   $tmp = $box[$i]; 
  26.   $box[$i] = $box[$j]; 
  27.   $box[$j] = $tmp
  28.  } 
  29.  for($a = $j = $i = 0; $i < $string_length$i++) { 
  30.   $a = ($a + 1) % 256; 
  31.   $j = ($j + $box[$a]) % 256; 
  32.   $tmp = $box[$a]; 
  33.   $box[$a] = $box[$j]; 
  34.   $box[$j] = $tmp
  35.   $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256])); 
  36.  } 
  37.  if($operation == 'decode') { 
  38.   if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {//开源代码phpfensi.com 
  39.    return substr($result, 26); 
  40.   } else { 
  41.    return ''
  42.   } 
  43.  } else { 
  44.   return $keyc.str_replace('='''base64_encode($result)); 
  45.  } 



zend