Create a hashing plugin in PHP codeigniter

We will start by creating a new file inside the system/application/plugins/ folder, called hash_pi.php.
Save the following code into the file. The logic is to split the password by half and use it as the point to insert the salt in encrypting the password.

function hash_password( $password, $salt)
$password_length = length($password) ;
$split_at = $password_length / 2;
$password_array = str_split( $password, $split_at) ;
$hash = sha1( $password_array[0 ] . $salt . $password_array[1] ) ;
return $hash;

To use the plugin, you have to load it into one of your Controllers, as follows:

$this->load->plugin( ' hash' ) ;

Then you can simply use the function as:

$hashed_password = hash_password($password, $salt) ;

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.