Cryptography PBKDF2

public class PBKDF2 extends Cryptography

class.pbkdf2.php #13

PBKDF2 is a cryptography class for hashing and comparing messages using the PBKDF2-Algorithm with salting. This is the most advanced hashing algorithm Symphony provides.

Constants

static str ALGORITHM = 'sha256'

Algorithm to be used

static int ITERATIONS = 10000

Key length

static int KEY_LENGTH = 40

Key length

static str PREFIX = 'PBKDF2v1'

Prefix to identify the algorithm used

static int SALT_LENGTH = 20

Salt length

Methods

static boolean compare(string $input, string $hash, boolean $isHash)

Compares a given hash with a cleantext password. Also extracts the salt from the hash.

Parameters
  • $input stringthe cleartext password

  • $hash stringthe hash the password should be checked against

Returns

the result of the comparison

See Also
static string extractHash(string $input)

Extracts the hash from a hash/salt-combination

Parameters
  • $input stringthe hashed string

Returns

the hash

static integer extractIterations(string $input)

Extracts the number of iterations from a hash/salt-combination

Parameters
  • $input stringthe hashed string

Returns

the number of iterations

static string extractSalt(string $input)

Extracts the salt from a hash/salt-combination

Parameters
  • $input stringthe hashed string

Returns

the salt

static integer extractSaltlength(string $input)

Extracts the saltlength from a hash/salt-combination

Parameters
  • $input stringthe hashed string

Returns

the saltlength

static string hash(string $input, string $salt, integer $iterations, string $keylength)

Uses PBKDF2 and random salt generation to create a hash based on some input. Original implementation was under public domain, taken from http://www.itnewb.com/tutorial/Encrypting-Passwords-with-PHP-for-Storage-Using-the-RSA-PBKDF2-Standard

Parameters
  • $input stringthe string to be hashed

  • $salt stringan optional salt

  • $iterations integeran optional number of iterations to be used

  • $keylength stringan optional length the key will be cropped to fit

Returns

the hashed string

See Also
static boolean requiresMigration(string $hash)

Checks if provided hash has been computed by most recent algorithm returns true if otherwise

Parameters
  • $hash stringthe hash to be checked

Returns

whether the hash should be re-computed

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details