secure_hash
[ class tree: secure_hash ] [ index: secure_hash ] [ all elements ]

Class: secure_hash

Source Location: /secure_hash/secure_hash.class.php

Class Overview


Secure password hashing class. A simple and easy to use class for secure password hashing. It is using random Salts and multiple hashing with random iterations. The class can be easily extended with own hashing methods.


Author(s):

Version:

  • v0.1_2009.09.18

Variables

Methods


Child classes:

secure_hash_example
Example code how secure_hash can be easily extended for own hashing methods.

Class Details

[line 36]
Secure password hashing class. A simple and easy to use class for secure password hashing. It is using random Salts and multiple hashing with random iterations. The class can be easily extended with own hashing methods.



Tags:

version:  v0.1_2009.09.18
access:  public
name:  Secure password hashing class


[ Top ]


Class Variables

$delimiter =  '$'

[line 51]

Delimiter used in formated hash



Tags:

access:  public

Type:   string


[ Top ]

$hashing_method =  'sha1'

[line 44]

Default hashing method

Check available _hash_* methods




Tags:

access:  public

Type:   string


[ Top ]

$iter_max =  99

[line 96]

Max hashing iterations

Keep this under 100 to keep hashlength static




Tags:

access:  public

Type:   int


[ Top ]

$iter_min =  10

[line 88]

Min hashing iterations

Keep this at least at 10 to keep hashlength static




Tags:

access:  public

Type:   int


[ Top ]

$permutate =  true

[line 103]

Flag if permutations should be used



Tags:

access:  public

Type:   bool


[ Top ]

$permutations = array('0123456789abcdef|e875d60c4a2f1b93',
                                          '0123456789abcdef|7d15b9f3e60a82c4',
                                          '0123456789abcdef|b294cd1e6a038f57')

[line 112]

Rules for permutation.

Add more rules to make hashing even more complex. Every rule gets applied




Tags:

access:  public

Type:   array


[ Top ]

$salt_chars =  '^!%&/()=?+~#,.-;:_|<>@$'

[line 67]

Salt chars.

Just using special latin chars here so we wont break charset and avoid creating not secure salts. NO " and ' to avoid breaking queries.




Tags:

access:  public

Type:   string


[ Top ]

$salt_global =  ''

[line 80]

Global salt which is NOT stored inside formated hash but needed to check integrity of hash.

This is a further security method to avoid hashes being cracked. Idea is to save salt in database, as well as in a config file or just here. A attacker would need access to both to gain enough data to crack these hashes. Changing this value leads to incorrect hashes. Just define it once and keep it.




Tags:

access:  public

Type:   string


[ Top ]

$salt_len =  4

[line 58]

Length of salt



Tags:

access:  public

Type:   int


[ Top ]



Class Methods


method check [line 157]

boolean check( string $hash_formated, string $pass)

Checks if a formated hash is equal to a password



Tags:

return:  true is hash == pass
access:  public


Parameters:

string   $hash_formated   hash to use
string   $pass   password to check

[ Top ]

method hash [line 127]

string hash( string $pass, [string $salt = false], [integer $iter = false])

Hashes a string and returns the formated hash.



Tags:

return:  hashed string
access:  public


Parameters:

string   $pass   string to hash
string   $salt   salt to use, default false
integer   $iter   iterations to do, default false

[ Top ]

method _hash_md5 [line 237]

string _hash_md5( string $str, string $salt, int $iter)

Plugin md5 hashing method



Tags:

access:  private


Parameters:

string   $str   string to hash
string   $salt   salt to use
int   $iter   iterations to do

[ Top ]

method _hash_sha1 [line 222]

string _hash_sha1( string $str, string $salt, int $iter)

Plugin sha1 hashing method



Tags:

access:  private


Parameters:

string   $str   string to hash
string   $salt   salt to use
int   $iter   iterations to do

[ Top ]

method _new_permutation [line 187]

string _new_permutation( [$b $b = false])

Returns a new permutaion which can be used in this class

Permutation format is abc|cab - a->c && b->a && c->b Default base is 0..f *




Tags:

return:  permutation for this class
access:  public


Parameters:

$b   $b   string base for permutation

[ Top ]

method _p [line 251]

string _p( string $str)

Permutation string with global rules



Tags:

return:  permutated string
access:  private


Parameters:

string   $str   string to permutate

[ Top ]

method _permutate [line 269]

bool _permutate( &$str, &$perm, [bool $dir = true], [integer $iter = false], string $str, string $perm)

Permutate a string with given rule



Tags:

return:  always true.
access:  private


Parameters:

string   $str   referece (faster) for the string to permutate
string   $perm   rule in form of 123|312
bool   $dir   direction to permutate. Default: true = forward
integer   $iter   number of iterations to do. Default: depends on last char and length of $perm.
   &$str  
   &$perm  

[ Top ]

method _salt [line 200]

string _salt( )

Generate a random salt



Tags:

access:  private


[ Top ]


Documentation generated on Fri, 29 Jan 2010 08:49:11 +0100 by phpDocumentor 1.4.3