Generating passwords with CodeIgniter – the bare bones

Okay, this is just the bare bones process. If you want a full example, then the preceding recipe is for you. This recipe is for people who already have a create-user process, but wish to integrate some password protection into an existing process.

How to do it...

If you don't need the preceding recipe and only require the bare bones of hashing/comparing; please refer to the following steps:

Generating a hash

To generate a hash, perform the following steps:

  1. Generate a hash with a key in $config['encryption_key'] as follows:
    // Call Encrypt library
    $this->load->library('encrypt');
    
    $hash = $this->encrypt->sha1($text_to_be_hashed);
  2. Generate a hash with a key other than that in $config['encryption_key'] ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.