Changeset 34 for trunk/phpgwapi/inc/adodb/session/crypt.inc.php
- Timestamp:
- 06/29/07 15:17:46 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpgwapi/inc/adodb/session/crypt.inc.php
r2 r34 62 62 63 63 } 64 65 66 class SHA1Crypt{ 67 68 function keyED($txt,$encrypt_key) 69 { 70 71 $encrypt_key = sha1($encrypt_key); 72 $ctr=0; 73 $tmp = ""; 74 75 for ($i=0;$i<strlen($txt);$i++){ 76 if ($ctr==strlen($encrypt_key)) $ctr=0; 77 $tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1); 78 $ctr++; 79 } 80 return $tmp; 81 82 } 83 84 85 86 function Encrypt($txt,$key) 87 { 88 89 srand((double)microtime()*1000000); 90 $encrypt_key = sha1(rand(0,32000)); 91 $ctr=0; 92 $tmp = ""; 93 94 for ($i=0;$i<strlen($txt);$i++) 95 96 { 97 98 if ($ctr==strlen($encrypt_key)) $ctr=0; 99 100 $tmp.= substr($encrypt_key,$ctr,1) . 101 102 (substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1)); 103 104 $ctr++; 105 106 } 107 108 return base64_encode($this->keyED($tmp,$key)); 109 110 } 111 112 113 114 function Decrypt($txt,$key) 115 { 116 117 $txt = $this->keyED(base64_decode($txt),$key); 118 119 $tmp = ""; 120 121 for ($i=0;$i<strlen($txt);$i++){ 122 123 $sha1 = substr($txt,$i,1); 124 125 $i++; 126 127 $tmp.= (substr($txt,$i,1) ^ $sha1); 128 129 } 130 131 return $tmp; 132 } 133 134 135 136 function RandPass() 137 { 138 $randomPassword = ""; 139 srand((double)microtime()*1000000); 140 141 for($i=0;$i<8;$i++) 142 { 143 144 $randnumber = rand(48,120); 145 146 while (($randnumber >= 58 && $randnumber <= 64) || ($randnumber >= 91 && $randnumber <= 96)) 147 { 148 $randnumber = rand(48,120); 149 } 150 151 $randomPassword .= chr($randnumber); 152 } 153 154 return $randomPassword; 155 156 } 157 158 159 160 } 64 161 ?>
Note: See TracChangeset
for help on using the changeset viewer.