Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for hashing algorithms other than SHA1 and MD5 #1847

Merged
merged 3 commits into from

4 participants

@unfunco

This allows the CI_Encrypt class to generate hashes using algorithms other than SHA1 and MD5, any algorithm available can be used and this is checked using the hash_algos() function, which is available in PHP versions earlier than the version required by CodeIgniter. This also retains backwards compatibility.

Signed-off-by: Daniel Morris daniel@honestempire.com

@unfunco unfunco Support for hashing algorithms other than SHA1 and MD5
Signed-off-by: Daniel Morris <daniel@honestempire.com>
a9923f5
@ckdarby

As the hashing extension requires no external libraries and is enabled by default in version PHP 5.1.2 this functionality makes sense.

@narfbg Worth looking at :)

@narfbg
Owner

Looks good! Can you add a changelog entry and remove the parenthesis around in_array() (they only make it a bit harder to read) ?

@narfbg narfbg merged commit 226e704 into from
@ckdarby

@daniel-honestempire Congrats on your first merge into the core & hopefully we'll see more pull requests from you :)

@unfunco

Thanks @ckdarby, and @narfbg. Hopefully the first of many!

@dchill42

Invalid doc reference:

user_guide_src/source/changelog.rst:209: WARNING: unknown document: libraries/encrypt

Should be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2012
  1. @unfunco

    Support for hashing algorithms other than SHA1 and MD5

    unfunco authored
    Signed-off-by: Daniel Morris <daniel@honestempire.com>
Commits on Oct 4, 2012
  1. @unfunco
  2. @unfunco
This page is out of date. Refresh to see the latest.
View
4 system/libraries/Encrypt.php
@@ -484,7 +484,7 @@ protected function _get_mode()
*/
public function set_hash($type = 'sha1')
{
- $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type;
+ $this->_hash_type = in_array($type, hash_algos()) ? $type : 'sha1';
}
// --------------------------------------------------------------------
@@ -497,7 +497,7 @@ public function set_hash($type = 'sha1')
*/
public function hash($str)
{
- return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str);
+ return hash($this->_hash_type, $str);
}
}
View
2  user_guide_src/source/changelog.rst
@@ -204,6 +204,8 @@ Release Date: Not Released
- Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments.
- Removed the default ``&nbsp;`` from a number of the configuration variables.
- Added the ability to use a proxy with the :doc:`XML-RPC Library <libraries/xmlrpc>`.
+ - :doc:`Encryption Library <libraries/encrypt>` changes include:
+ - Added support for hashing algorithms other than SHA1 and MD5.
- Core
Something went wrong with that request. Please try again.