Documentation TYPO3 par Ameos |
00001 <?php 00002 // Session Encryption by Ari Kuorikoski <ari.kuorikoski@finebyte.com> 00003 class MD5Crypt{ 00004 function keyED($txt,$encrypt_key) 00005 { 00006 $encrypt_key = md5($encrypt_key); 00007 $ctr=0; 00008 $tmp = ""; 00009 for ($i=0;$i<strlen($txt);$i++){ 00010 if ($ctr==strlen($encrypt_key)) $ctr=0; 00011 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); 00012 $ctr++; 00013 } 00014 return $tmp; 00015 } 00016 00017 function Encrypt($txt,$key) 00018 { 00019 srand((double)microtime()*1000000); 00020 $encrypt_key = md5(rand(0,32000)); 00021 $ctr=0; 00022 $tmp = ""; 00023 for ($i=0;$i<strlen($txt);$i++) 00024 { 00025 if ($ctr==strlen($encrypt_key)) $ctr=0; 00026 $tmp.= substr($encrypt_key,$ctr,1) . 00027 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); 00028 $ctr++; 00029 } 00030 return base64_encode($this->keyED($tmp,$key)); 00031 } 00032 00033 function Decrypt($txt,$key) 00034 { 00035 $txt = $this->keyED(base64_decode($txt),$key); 00036 $tmp = ""; 00037 for ($i=0;$i<strlen($txt);$i++){ 00038 $md5 = substr($txt,$i,1); 00039 $i++; 00040 $tmp.= (substr($txt,$i,1) ^ $md5); 00041 } 00042 return $tmp; 00043 } 00044 00045 function RandPass() 00046 { 00047 $randomPassword = ""; 00048 srand((double)microtime()*1000000); 00049 for($i=0;$i<8;$i++) 00050 { 00051 $randnumber = rand(48,120); 00052 00053 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96)) 00054 { 00055 $randnumber = rand(48,120); 00056 } 00057 00058 $randomPassword .= chr($randnumber); 00059 } 00060 return $randomPassword; 00061 } 00062 00063 } 00064 ?>