Skip to content
Jeff Johns edited this page Jan 31, 2014 · 2 revisions
Name Path
Hash Helper /application/helpers/hash_helper.php

These encryption methods will do the base64 encoding and decoding for you. It is wise to use the base64 version of the encrypted string for database storage as there are no conflicting DB characters present and it can be decoded back to the raw hash easily.

Load the helper

$this->load->helper('hash_helper');

Methods

generateCSRF

Creates and returns a random 50 character string to be used for CSRF authentication.

Example

$csrf_token = generateCSRF();

generateHash

Create a secure hash of a string. It cycles thru different encryption types from best to worst and returns a one-way encrypted string.

Arguments

Variable Type Default Required Description
$str string N/A Yes The string to create a hash for

Example

$password = generateHash('Your String');

generatePassword

Creates a 12 character password that has at least one capital letter, one lowercase letter and one numeric.

Example

$password = generatePassword();

generateToken

Creates a random token at the length specified.

Arguments

Variable Type Default Required Description
$len integer 20 Yes The length of the token

Example

$token = generateToken();

isStrong

Evaluates each letter of the string. It looks for at least one capital letter, one lower case and one numeric to return true.

Arguments

Variable Type Default Required Description
$str String N/A Yes The string to evaluate.

Example

if (isStong($str) === true) {
    // Good for you
}

verifyHash

Compares a base64 encoded hash against a plain text string to see if they match. This function will base64 decode the encoded string for you and use it as a salt for comparisons.

Arguments

Variable Type Default Required Description
$str string N/A Yes The string to evaluate against
$hash string N/A Yes The base64 encoded, crypt string to use for the sale

Example

if (verifyHash('Your String', $encrypted_password)) {
    //Hey it works!
}