示例#1
0
 /**
  * @param string $encoded_str
  * @return ks
  */
 public static function fromSecureString($encoded_str)
 {
     if (empty($encoded_str)) {
         return null;
     }
     $str = base64_decode($encoded_str, true);
     // encode this string
     $ks = new ks();
     $real_str = $str;
     @(list($hash, $real_str) = @explode("|", $str, 2));
     //		echo "[$str]<br>[$hash]<br>[$real_str]<br>[" . self::hash ( $real_str ) . "]<br>";
     $ks->original_str = $encoded_str;
     $parts = explode(self::SEPARATOR, $real_str);
     list($ks->partner_id, $ks->partner_pattern, $ks->valid_until, $ks->type, $ks->rand, ) = $parts;
     if (isset($parts[5])) {
         $ks->user = $parts[5];
     }
     if (isset($parts[6])) {
         $ks->privileges = $parts[6];
     }
     if (isset($parts[7])) {
         $ks->master_partner_id = $parts[7];
     }
     if (isset($parts[8])) {
         $ks->additional_data = $parts[8];
     }
     $salt = $ks->getSalt();
     if (self::hash($salt, $real_str) != $hash) {
         throw new Exception(self::getErrorStr(self::INVALID_STR));
         //$ks->valid_string = false;
         //return $ks;
     }
     $ks->valid_string = true;
     return $ks;
 }