security.php
Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class Security extends Object {
00039
00040
00041
00042
00043
00044
00045 function &getInstance() {
00046 static $instance = array();
00047 if (!$instance) {
00048 $instance[0] = &new Security;
00049 }
00050 return $instance[0];
00051 }
00052
00053
00054
00055
00056
00057
00058 function inactiveMins() {
00059 switch(CAKE_SECURITY) {
00060 case 'high':
00061 return 10;
00062 break;
00063 case 'medium':
00064 return 100;
00065 break;
00066 case 'low':
00067 default:
00068 return 300;
00069 break;
00070 }
00071 }
00072
00073
00074
00075
00076
00077
00078 function generateAuthKey() {
00079 $_this =& Security::getInstance();
00080 return $_this->hash(uniqid(rand(), true));
00081 }
00082
00083
00084
00085
00086
00087
00088
00089 function validateAuthKey($authKey) {
00090 return true;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100 function hash($string, $type = 'sha1') {
00101 $type = strtolower($type);
00102 if ($type == 'sha1') {
00103 if (function_exists('sha1')) {
00104 $return = sha1($string);
00105 return $return;
00106 } else {
00107 $type = 'sha256';
00108 }
00109 }
00110
00111 if ($type == 'sha256') {
00112 if (function_exists('mhash')) {
00113 $return = bin2hex(mhash(MHASH_SHA256, $string));
00114 return $return;
00115 } else {
00116 $type = 'md5';
00117 }
00118 }
00119
00120 if ($type == 'md5') {
00121 $return = md5($string);
00122 return $return;
00123 }
00124 }
00125
00126
00127
00128
00129
00130
00131
00132
00133 function cipher($text, $key) {
00134 if (!defined('CIPHER_SEED')) {
00135
00136 define('CIPHER_SEED', '76859309657453542496749683645');
00137 }
00138 srand (CIPHER_SEED);
00139 $out = '';
00140
00141 for ($i = 0; $i < strlen($text); $i++) {
00142 for ($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) {
00143 $toss = rand(0, 255);
00144 }
00145 $mask = rand(0, 255);
00146 $out .= chr(ord(substr($text, $i, 1)) ^ $mask);
00147 }
00148 return $out;
00149 }
00150 }
00151 ?>