Skip to content

Instantly share code, notes, and snippets.

@mbuyco
Last active May 22, 2021 20:11
Show Gist options
  • Save mbuyco/6109108 to your computer and use it in GitHub Desktop.
Save mbuyco/6109108 to your computer and use it in GitHub Desktop.
CodeIgniter Password Hash Library installation tutorial by mac_devin

DISCLAIMER: I do not own any of the source codes provided below. This is only a tutorial on how to install CodeIgniter-Phpass-Library in your CodeIgniter applications. If you want to see the original tutorial, please go to this link: https://github.com/jenssegers/CodeIgniter-Phpass-Library

CodeIgniter Password Hash Library

phpass is a portable password hashing framework for use in PHP applications. The preferred (most secure) hashing method supported by phpass is the OpenBSD-style bcrypt (known in PHP as CRYPT_BLOWFISH), with a fallback to BSDI-style extended DES-based hashes (known in PHP as CRYPT_EXT_DES), and a last resort fallback to an MD5-based variable iteration count password hashing method implemented in phpass itself.

Installation

  1. Download this .zip file: https://github.com/jenssegers/CodeIgniter-Phpass-Library/archive/master.zip
  2. From the downloaded files, copy the libraries and vendor folder into your CodeIgniter application folder.
  3. Copy the phpass.php from the config folder of your download files and paste in your CodeIgniter's application/config folder.
  4. Please follow the instructions below on how to use this hash library.

How to use:

<?php
// Load the hash library
$this->load->library('phpass'); // or use spark

// example 1: hashing a password
$password = $this->input->post('password');
$hashed = $this->phpass->hash($password);

// example 2: checking a password
$user = $this->user_model->get(123);
$hashed = $user->password;
$password = $this->input->post('password');

if ($this->phpass->check($password, $hashed))
    echo 'logged in';
else
    echo 'wrong password';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment