[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
2006-01-17 05:13:38 +00:00
|
|
|
*
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2006-01-17 05:13:38 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v .0.10.0.1233
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
2006-01-17 05:13:38 +00:00
|
|
|
*
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
* Long description for file
|
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
*/
|
2006-05-26 05:29:17 +00:00
|
|
|
class Security extends Object{
|
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Singleton implementation to get object instance.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @return object
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
|
|
|
function &getInstance() {
|
|
|
|
static $instance = array();
|
|
|
|
if (!$instance) {
|
2006-08-03 06:49:51 +00:00
|
|
|
$instance[0] =& new Security;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
|
|
|
return $instance[0];
|
|
|
|
}
|
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Get allowed minutes of inactivity based on security level.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @return int Allowed inactivity in minutes
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
|
|
|
function inactiveMins() {
|
2006-08-03 06:49:51 +00:00
|
|
|
$_this =& Security::getInstance();
|
2006-05-26 05:29:17 +00:00
|
|
|
switch(CAKE_SECURITY) {
|
|
|
|
case 'high':
|
|
|
|
return 10;
|
|
|
|
break;
|
|
|
|
case 'medium':
|
|
|
|
return 100;
|
|
|
|
break;
|
|
|
|
case 'low':
|
|
|
|
default:
|
|
|
|
return 300;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Generate authorization hash.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @return string Hash
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
|
|
|
function generateAuthKey() {
|
|
|
|
$_this =& Security::getInstance();
|
|
|
|
return $_this->hash(uniqid(rand(), true));
|
|
|
|
}
|
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Validate authorization hash.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @param string $authKey Authorization hash
|
|
|
|
* @return boolean Success
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
2006-08-03 06:49:51 +00:00
|
|
|
function validateAuthKey($authKey) {
|
|
|
|
$_this =& Security::getInstance();
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Create a hash from string using given method.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @param string $string String to hash
|
|
|
|
* @param string $type Method to use (sha1/sha256/md5)
|
|
|
|
* @return string Hash
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
2006-08-03 06:49:51 +00:00
|
|
|
function hash($string, $type = 'sha1') {
|
|
|
|
$_this =& Security::getInstance();
|
|
|
|
$type = strtolower($type);
|
|
|
|
if ($type == 'sha1') {
|
|
|
|
if (function_exists('sha1')) {
|
|
|
|
$return = sha1($string);
|
|
|
|
return $return;
|
|
|
|
} else {
|
|
|
|
$type = 'sha256';
|
|
|
|
}
|
|
|
|
}
|
2006-01-17 05:13:38 +00:00
|
|
|
|
2006-08-03 06:49:51 +00:00
|
|
|
if ($type == 'sha256') {
|
|
|
|
if (function_exists('mhash')) {
|
|
|
|
$return = bin2hex(mhash(MHASH_SHA256, $string));
|
|
|
|
return $return;
|
|
|
|
} else {
|
|
|
|
$type = 'md5';
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-08-03 06:49:51 +00:00
|
|
|
}
|
2006-01-17 05:13:38 +00:00
|
|
|
|
2006-08-03 06:49:51 +00:00
|
|
|
if ($type == 'md5') {
|
|
|
|
$return = md5($string);
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|
2006-05-26 05:29:17 +00:00
|
|
|
/**
|
2007-05-26 06:35:44 +00:00
|
|
|
* Encripts/Decrypts a text using the given key.
|
2006-05-26 05:29:17 +00:00
|
|
|
*
|
2007-05-26 06:35:44 +00:00
|
|
|
* @param string $text Encrypted string to decrypt, normal string to encrypt
|
|
|
|
* @param string $key Key to use
|
|
|
|
* @return string Encrypted/Decrypted string
|
|
|
|
* @access public
|
|
|
|
* @static
|
2006-05-26 05:29:17 +00:00
|
|
|
*/
|
2006-08-03 06:49:51 +00:00
|
|
|
function cipher($text, $key) {
|
|
|
|
$_this =& Security::getInstance();
|
|
|
|
if (!defined('CIPHER_SEED')) {
|
|
|
|
//This is temporary will change later
|
|
|
|
define('CIPHER_SEED', '76859309657453542496749683645');
|
|
|
|
}
|
|
|
|
srand (CIPHER_SEED);
|
|
|
|
$out = '';
|
2006-01-17 05:13:38 +00:00
|
|
|
|
2006-08-03 06:49:51 +00:00
|
|
|
for($i = 0; $i < strlen($text); $i++) {
|
|
|
|
for($j = 0; $j < ord(substr($key, $i % strlen($key), 1)); $j++) {
|
|
|
|
$toss = rand(0, 255);
|
|
|
|
}
|
|
|
|
$mask = rand(0, 255);
|
|
|
|
$out .= chr(ord(substr($text, $i, 1)) ^ $mask);
|
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2005-11-05 04:08:14 +00:00
|
|
|
}
|
[1242]
Author: phpnut
Date: 6:19:00 PM, Thursday, October 27, 2005
Message:
removing session directory
[1241]
Author: phpnut
Date: 6:13:46 PM, Thursday, October 27, 2005
Message:
added docblocks and temp error messages when trying to use the unimplemeted database for sessions
[1239]
Author: phpnut
Date: 5:28:57 PM, Thursday, October 27, 2005
Message:
More work on session.
Added config settings to core.php
updated model to allow models without a database table.
[1237]
Author: phpnut
Date: 3:50:27 PM, Thursday, October 27, 2005
Message:
adding directories for sessions
[1235]
Author: phpnut
Date: 3:36:08 AM, Thursday, October 27, 2005
Message:
Typo
[1234]
Author: phpnut
Date: 3:34:07 AM, Thursday, October 27, 2005
Message:
More work on the Session classes and adding the first methods the to Security class
[1233]
Author: phpnut
Date: 3:05:46 AM, Thursday, October 27, 2005
Message:
Start to core security class added.
Moved paths.php to cake/config/
Refactoring Session classes
[1232]
Author: phpnut
Date: 2:20:25 AM, Thursday, October 27, 2005
Message:
More work on the core session class.
Adding session component class.
Added fix for errors messages not working with validation.
Added possible fix for inflector now working on the word status.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1243 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-27 23:29:56 +00:00
|
|
|
?>
|