Revision: 23798
Updated Code
at February 13, 2010 05:01 by Keef
Updated Code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter Extended Encryption Class * * An extension to CI's encryption class to provide a lot more hash algorithms. PHP * 5.1.2+ is highly recommended to take full advantage of this class, however extra * user made hash functions can be used as if they are added to the * 'MY_Encrypt::_custom_hashes' array. * * @package CodeIgniter * @subpackage Extended libraries * @category Extended libraries * @author Jeffy * @link */ class MY_Encrypt extends CI_Encrypt { // Built-in CodeIgniter hash algorithms var $_builtin_hashes = array( 'sha1', 'md5', ); // Custom hash algorithms var $_custom_hashes = array( ); function MY_Encrypt() { parent::CI_Encrypt(); } function set_hash($type = 'sha1') { if ($this->hash_exists($type)) { $this->_hash_type = $type; } } function hash($str) { if ($this->hash_exists($this->_hash_type)) { // CodeIgniter built-in hashes if (in_array($this->_hash_type, $this->_builtin_hashes)) { return parent::hash($str); // Hash algorithms available using the PHP5 'hash' function } elseif (function_exists('hash') AND in_array($this->_hash_type, @hash_algos())) { return hash($this->_hash_type, $str); // Hash algorithms available using the PHP5 'openssl_digest' function } elseif (function_exists('openssl_digest') AND in_array($this->_hash_type, @openssl_get_md_methods())) { return openssl_digest($str, $this->_hash_type); // Custom hash functions/algorithms referenced by the $_custom_hashes array } elseif (@in_array($this->_hash_type, $this->_custom_hashes)) { if (method_exists($this, $this->_hash_type)) { return call_user_func(array($this, $this->_hash_type), $str); } } } else { // Default to SHA1 instead of MD5. $this->_hash_type = 'sha1'; return parent::hash($str); } } function hash_exists($type) { return ( in_array($type, $this->_builtin_hashes) OR in_array($type, $this->_custom_hashes) OR function_exists('hash') AND in_array($type, @hash_algos()) OR function_exists('openssl_digest') AND in_array($type, @openssl_get_md_methods()) ); } } ?>
Revision: 23797
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 13, 2010 04:55 by Keef
Initial Code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter Extended Encryption Class * * An extension to CI's encryption class to provide a lot more hash algorithms/functions. PHP 5.1.2+ is highly recommended to take full advantage of this class however extra user made hash functions can be used as if they are added to the 'MY_Encrypt::_custom_hashes' array. * * @package CodeIgniter * @subpackage Extended libraries * @category Extended libraries * @author Jeffy * @link */ class MY_Encrypt extends CI_Encrypt { // Built-in CodeIgniter hash algorithms var $_builtin_hashes = array( 'sha1', 'md5', ); // Custom hash algorithms var $_custom_hashes = array( ); function MY_Encrypt() { parent::CI_Encrypt(); } function set_hash($type = 'sha1') { if ($this->hash_exists($type)) { $this->_hash_type = $type; } } function hash($str) { if ($this->hash_exists($this->_hash_type)) { // CodeIgniter built-in hashes if (in_array($this->_hash_type, $this->_builtin_hashes)) { return parent::hash($str); // Hash algorithms available using the PHP5 'hash' function } elseif (function_exists('hash') AND in_array($this->_hash_type, @hash_algos())) { return hash($this->_hash_type, $str); // Hash algorithms available using the PHP5 'openssl_digest' function } elseif (function_exists('openssl_digest') AND in_array($this->_hash_type, @openssl_get_md_methods())) { return openssl_digest($str, $this->_hash_type); // Custom hash functions/algorithms referenced by the $_custom_hashes array } elseif (@in_array($this->_hash_type, $this->_custom_hashes)) { if (method_exists($this, $this->_hash_type)) { return call_user_func(array($this, $this->_hash_type), $str); } } } else { // Default to SHA1 instead of MD5. $this->_hash_type = 'sha1'; return parent::hash($str); } } function hash_exists($type) { return ( in_array($type, $this->_builtin_hashes) OR in_array($type, $this->_custom_hashes) OR function_exists('hash') AND in_array($type, @hash_algos()) OR function_exists('openssl_digest') AND in_array($type, @openssl_get_md_methods()) ); } } ?>
Initial URL
Initial Description
Initial Title
CodeIgniter Extended Encryption Class
Initial Tags
codeigniter
Initial Language
PHP