PHP Class PassHash, dokuwiki

Mostrar archivo Open project: splitbrain/dokuwiki Class Usage Examples

Public Methods

Method Description
gen_salt ( integer $len = 32 ) : string Create a random salt
hash_apr1 ( string $clear, string $salt = null, string $magic = 'apr1' ) : string Password hashing method 'apr1'
hash_bcrypt ( string $clear, string $salt = null, integer $compute = 8 ) : string Passwordhashing method 'bcrypt'
hash_crypt ( string $clear, string $salt = null ) : string Password hashing method 'crypt'
hash_djangomd5 ( string $clear, string $salt = null ) : string Password hashing method 'djangomd5'
hash_djangopbkdf2 ( string $clear, string $salt = null, array $opts = [] ) : string Password hashing method 'djangopbkdf2'
hash_djangopbkdf2_sha1 ( string $clear, string $salt = null, array $opts = [] ) : string Alias for djangopbkdf2 defaulting to sha1 as hash algorithm
hash_djangopbkdf2_sha256 ( string $clear, string $salt = null, array $opts = [] ) : string Alias for djangopbkdf2 defaulting to sha256 as hash algorithm
hash_djangosha1 ( string $clear, string $salt = null ) : string Password hashing method 'djangosha1'
hash_hmd5 ( $clear, $salt = null, $magic = 'H', $compute = 8 ) Alias for hash_pmd5
hash_kmd5 ( string $clear, string $salt = null ) : string Password hashing method 'kmd5'
hash_lsmd5 ( string $clear, string $salt = null ) : string Password hashing method 'lsmd5'
hash_md5 ( string $clear ) : string Password hashing method 'md5'
hash_mediawiki ( string $clear, string $salt = null ) : string Password hashing method 'mediawiki'
hash_my411 ( string $clear ) : string Password hashing method 'my411'
hash_mysql ( string $clear ) : string Password hashing method 'mysql'
hash_pmd5 ( string $clear, string $salt = null, string $magic = 'P', integer $compute = 8 ) : string Password hashing method 'pmd5'
hash_sha1 ( string $clear ) : string Password hashing method 'sha1'
hash_sha512 ( string $clear, string $salt = null ) : string Password hashing method SHA512
hash_smd5 ( string $clear, string $salt = null ) : string Password hashing method 'smd5'
hash_ssha ( string $clear, string $salt = null ) : string Password hashing method 'ssha' as used by LDAP
hmac ( string $algo, string $data, string $key, boolean $raw_output = false ) : string Wraps around native hash_hmac() or reimplents it
init_salt ( &$salt, integer $len = 32, boolean $cut = true ) Initialize the passed variable with a salt if needed.
verify_hash ( string $clear, string $hash ) : boolean Verifies a cleartext password against a crypted hash

Protected Methods

Method Description
random ( integer $min, integer $max ) : integer Use DokuWiki's secure random generator if available

Method Details

gen_salt() public method

Create a random salt
public gen_salt ( integer $len = 32 ) : string
$len integer The length of the salt
return string

hash_apr1() public method

Uses salted MD5 hashs. Salt is 8 bytes long. This is basically the same as smd1 above, but as used by Apache.
public hash_apr1 ( string $clear, string $salt = null, string $magic = 'apr1' ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$magic string The hash identifier (apr1 or 1)
return string Hashed password

hash_bcrypt() public method

Uses a modified blowfish algorithm called eksblowfish This method works on PHP 5.3+ only and will throw an exception if the needed crypt support isn't available A full hash should be given as salt (starting with $a2$) or this will break. When no salt is given, the iteration count can be set through the $compute variable.
public hash_bcrypt ( string $clear, string $salt = null, integer $compute = 8 ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$compute integer The iteration count (between 4 and 31)
return string Hashed password

hash_crypt() public method

Uses salted crypt hashs. Salt is 2 bytes long.
public hash_crypt ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_djangomd5() public method

Uses salted MD5 hashs. Salt is 5 bytes long. This is used by the Django Python framework
public hash_djangomd5 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_djangopbkdf2() public method

An algorithm and iteration count should be given in the opts array. Defaults to sha256 and 24000 iterations
public hash_djangopbkdf2 ( string $clear, string $salt = null, array $opts = [] ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$opts array ('algo' => hash algorithm, 'iter' => iterations)
return string Hashed password

hash_djangopbkdf2_sha1() public method

Alias for djangopbkdf2 defaulting to sha1 as hash algorithm
public hash_djangopbkdf2_sha1 ( string $clear, string $salt = null, array $opts = [] ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$opts array ('iter' => iterations)
return string Hashed password

hash_djangopbkdf2_sha256() public method

Alias for djangopbkdf2 defaulting to sha256 as hash algorithm
public hash_djangopbkdf2_sha256 ( string $clear, string $salt = null, array $opts = [] ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$opts array ('iter' => iterations)
return string Hashed password

hash_djangosha1() public method

Uses salted SHA1 hashs. Salt is 5 bytes long. This is used by the Django Python framework
public hash_djangosha1 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_hmd5() public method

Alias for hash_pmd5
public hash_hmd5 ( $clear, $salt = null, $magic = 'H', $compute = 8 )

hash_kmd5() public method

Uses salted MD5 hashs. Salt is 2 bytes long, but stored at position 16, so you need to pass at least 18 bytes. You can pass the crypted hash as salt.
public hash_kmd5 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_lsmd5() public method

Uses salted MD5 hashs. Salt is 8 bytes long. This is the format used by LDAP.
public hash_lsmd5 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_md5() public method

Uses MD5 hashs.
public hash_md5 ( string $clear ) : string
$clear string The clear text to hash
return string Hashed password

hash_mediawiki() public method

Uses salted MD5, this is referred to as Method B in MediaWiki docs. Unsalted md5 method 'A' is not supported.
public hash_mediawiki ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_my411() public method

Uses SHA1 hashs. This method is used by MySQL 4.11 and above
public hash_my411 ( string $clear ) : string
$clear string The clear text to hash
return string Hashed password

hash_mysql() public method

This method was used by old MySQL systems
public hash_mysql ( string $clear ) : string
$clear string The clear text to hash
return string Hashed password

hash_pmd5() public method

Uses salted MD5 hashs. Salt is 1+8 bytes long, 1st byte is the iteration count when given, for null salts $compute is used. The actual iteration count is the given count squared, maximum is 30 (-> 1073741824). If a higher one is given, the function throws an exception.
public hash_pmd5 ( string $clear, string $salt = null, string $magic = 'P', integer $compute = 8 ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
$magic string The hash identifier (P or H)
$compute integer The iteration count for new passwords
return string Hashed password

hash_sha1() public method

Uses SHA1 hashs.
public hash_sha1 ( string $clear ) : string
$clear string The clear text to hash
return string Hashed password

hash_sha512() public method

This is only supported on PHP 5.3.2 or higher and will throw an exception if the needed crypt support is not available
public hash_sha512 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_smd5() public method

Uses salted MD5 hashs. Salt is 8 bytes long. The same mechanism is used by Apache's 'apr1' method. This will fallback to a implementation in pure PHP if MD5 support is not available in crypt()
public hash_smd5 ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hash_ssha() public method

Uses salted SHA1 hashs. Salt is 4 bytes long.
public hash_ssha ( string $clear, string $salt = null ) : string
$clear string The clear text to hash
$salt string The salt to use, null for random
return string Hashed password

hmac() public static method

This is not directly used as password hashing method, and thus isn't callable via the verify_hash() method. It should be used to create signatures and might be used in other password hashing methods.
See also: hash_hmac()
Author: KC Cloyd
public static hmac ( string $algo, string $data, string $key, boolean $raw_output = false ) : string
$algo string Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..) See hash_algos() for a list of supported algorithms.
$data string Message to be hashed.
$key string Shared secret key used for generating the HMAC variant of the message digest.
$raw_output boolean When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits.
return string

init_salt() public method

If $salt is not null, the value is kept, but the lenght restriction is applied (unless, $cut is false).
public init_salt ( &$salt, integer $len = 32, boolean $cut = true )
$len integer The length of the salt
$cut boolean Apply length restriction to existing salt?

random() protected method

Use DokuWiki's secure random generator if available
protected random ( integer $min, integer $max ) : integer
$min integer
$max integer
return integer

verify_hash() public method

The method and salt used for the crypted hash is determined automatically, then the clear text password is crypted using the same method. If both hashs match true is is returned else false
Author: Andreas Gohr ([email protected])
public verify_hash ( string $clear, string $hash ) : boolean
$clear string Clear-Text password
$hash string Hash to compare against
return boolean