class CryptConnector in Acquia Connector 8.2
Same name and namespace in other branches
- 8 src/CryptConnector.php \Drupal\acquia_connector\CryptConnector
- 3.x src/CryptConnector.php \Drupal\acquia_connector\CryptConnector
Class CryptConnector.
Extends secure password hashing functions based on the Portable PHP password hashing framework.
@package Drupal\acquia_connector
Hierarchy
- class \Drupal\Core\Password\PhpassHashedPassword implements PasswordInterface
- class \Drupal\acquia_connector\CryptConnector
Expanded class hierarchy of CryptConnector
1 file declares its use of CryptConnector
- NspiController.php in tests/
modules/ src/ Controller/ NspiController.php
File
- src/
CryptConnector.php, line 15
Namespace
Drupal\acquia_connectorView source
class CryptConnector extends PhpassHashedPassword {
/**
* The string name of a hashing algorithm usable by hash(), like 'sha256'.
*
* @var string
*/
private $algo;
/**
* Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to hash.
*
* @var string
*/
private $password;
/**
* An existing hash or the output of $this->generateSalt().
*
* @var string
*/
private $setting;
/**
* CryptConnector constructor.
*
* @param string $algo
* The string name of a hashing algorithm usable by hash(), like 'sha256'.
* @param string $password
* Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to
* hash.
* @param string $setting
* An existing hash or the output of $this->generateSalt(). Must be at least
* 12 characters (the settings and salt).
* @param mixed $extra_md5
* (Deprecated) If not empty password needs to be hashed with MD5 first.
*/
public function __construct($algo, $password, $setting, $extra_md5) {
$this->algo = $algo;
$this->password = $password;
$this->setting = $setting;
}
/**
* Crypt pass.
*
* @return string
* Crypt password.
*/
public function cryptPass() {
$crypt_pass = $this
->crypt($this->algo, $this->password, $this->setting);
return $crypt_pass;
}
/**
* Helper function. Calculate sha1 hash.
*
* @param string $key
* Acquia Subscription Key.
* @param string $string
* String to calculate hash.
*
* @return string
* Sha1 string.
*/
public static function acquiaHash($key, $string) {
return sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x5c), 64)) . pack("H*", sha1((str_pad($key, 64, chr(0x0)) ^ str_repeat(chr(0x36), 64)) . $string)));
}
/**
* Derive a key for the solr hmac using a salt, id and key.
*
* @param string $salt
* Salt.
* @param string $id
* Acquia Subscription ID.
* @param string $key
* Acquia Subscription Key.
*
* @return string
* Derived Key.
*/
public static function createDerivedKey($salt, $id, $key) {
$derivation_string = $id . 'solr' . $salt;
return hash_hmac('sha1', str_pad($derivation_string, 80, $derivation_string), $key);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CryptConnector:: |
private | property | The string name of a hashing algorithm usable by hash(), like 'sha256'. | |
CryptConnector:: |
private | property | Plain-text password up to 512 bytes (128 to 512 UTF-8 characters) to hash. | |
CryptConnector:: |
private | property | An existing hash or the output of $this->generateSalt(). | |
CryptConnector:: |
public static | function | Helper function. Calculate sha1 hash. | |
CryptConnector:: |
public static | function | Derive a key for the solr hmac using a salt, id and key. | |
CryptConnector:: |
public | function | Crypt pass. | |
CryptConnector:: |
public | function |
CryptConnector constructor. Overrides PhpassHashedPassword:: |
|
PasswordInterface:: |
constant | Maximum password length. | ||
PhpassHashedPassword:: |
protected | property | Specifies the number of times the hashing function will be applied when generating new password hashes. The number of times is calculated by raising 2 to the power of the given value. | |
PhpassHashedPassword:: |
public static | property | Returns a string for mapping an int to the corresponding base 64 character. | |
PhpassHashedPassword:: |
protected | function | Encodes bytes into printable base 64 using the *nix standard from crypt(). | |
PhpassHashedPassword:: |
public | function |
Check whether a plain text password matches a hashed password. Overrides PasswordInterface:: |
|
PhpassHashedPassword:: |
protected | function | Hash a password using a secure stretched hash. | |
PhpassHashedPassword:: |
protected | function | Ensures that $count_log2 is within set bounds. | 1 |
PhpassHashedPassword:: |
protected | function | Generates a random base 64-encoded salt prefixed with hash settings. | |
PhpassHashedPassword:: |
public | function | Parses the log2 iteration count from a stored hash or setting string. | |
PhpassHashedPassword:: |
public | function |
Hash a password using a secure hash. Overrides PasswordInterface:: |
|
PhpassHashedPassword:: |
constant | The expected (and maximum) number of characters in a hashed password. | ||
PhpassHashedPassword:: |
constant | The maximum allowed log2 number of iterations for password stretching. | ||
PhpassHashedPassword:: |
constant | The minimum allowed log2 number of iterations for password stretching. | ||
PhpassHashedPassword:: |
public | function |
Check whether a hashed password needs to be replaced with a new hash. Overrides PasswordInterface:: |