Advertisement
bkader

CodeIgniter Hash Helper

Jan 1st, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. /**
  5.  * Hash Helper
  6.  *
  7.  * @package     CodeIgniter
  8.  * @subpackage  Helpers
  9.  * @category    Hash Helper
  10.  * @author      Kader Bouyakoub <bkader@mail.com>
  11.  * @link        @KaderBouyakoub
  12.  *
  13.  */
  14.  
  15. if ( ! function_exists('generate_salt'))
  16. {
  17.     /**
  18.      * Generate a random SALT
  19.      *
  20.      * @access  public
  21.      * @param   integer
  22.      * @return  string
  23.      */
  24.     function generate_salt($length = 8)
  25.     {
  26.         if ($length > 32) $length = 32;
  27.         return substr(md5(microtime()), 0, $length);
  28.     }
  29. }
  30.  
  31. if ( ! function_exists('hash_password'))
  32. {
  33.     /**
  34.      * Hash a password
  35.      *
  36.      * @access  public
  37.      * @param   string
  38.      * @param   string
  39.      * @return  string
  40.      */
  41.     function hash_password($password, $salt)
  42.     {
  43.         // Make sure you use your own method and
  44.         // KEEP IT SECRET ;)
  45.         return md5(md5($salt.':'.md5($password)));
  46.     }
  47. }
  48.  
  49. if ( ! function_exists('check_password'))
  50. {
  51.     /**
  52.      * Compare between two password
  53.      *
  54.      * @access  public
  55.      * @param   string
  56.      * @param   string
  57.      * @param   string
  58.      * @return  boolean
  59.      */
  60.     function check_password($password, $salt, $hashed)
  61.     {
  62.         $_hased = hash_password($password, $salt);
  63.         return $_hased === $hashed;
  64.     }
  65. }
  66.  
  67. /* End of file hash_helper.php */
  68. /* Location: ./application/helpers/hash_helper.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement