/**
  * Set adapter options.
  *
  * Expects an associative array of option keys and values used to configure
  * the hash adapter instance.
  *
  * <dl>
  *   <dt>iterationCount</dt>
  *     <dd>An integer value between 1,000 and 999,999,999, inclusive. This
  *     value determines the cost factor associated with generating a new
  *     hash value. A higher number means a higher cost. Defaults to
  *     40,000.</dd>
  * </dl>
  *
  * @param Array $options
  *   Associative array of adapter options.
  * @return Bcrypt
  * @see Base::setOptions()
  */
 public function setOptions(array $options)
 {
     parent::setOptions($options);
     $options = array_change_key_case($options, CASE_LOWER);
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'iterationcountlog2':
                 $value = 1 << (int) $value;
                 // Fall through
             // Fall through
             case 'iterationcount':
                 $value = (int) $value;
                 if ($value < 1000 || $value > 999999) {
                     throw new InvalidArgumentException('Iteration count must be between 1000 and 999999');
                 }
                 $this->_iterationCount = $value;
                 break;
             default:
                 break;
         }
     }
     return $this;
 }
示例#2
0
 /**
  * Set adapter options.
  *
  * Expects an associative array of option keys and values used to configure
  * the hash adapter instance.
  *
  * <dl>
  *   <dt>iterationCount</dt>
  *     <dd>An integer value between 1 and 4294967295, inclusive. This
  *     value determines the cost factor associated with generating a new
  *     hash value. A higher number means a higher cost. Defaults to
  *     40000.</dd>
  * </dl>
  *
  * @param Array $options
  *   Associative array of adapter options.
  * @return Bcrypt
  * @see Base::setOptions()
  */
 public function setOptions(array $options)
 {
     parent::setOptions($options);
     $options = array_change_key_case($options, CASE_LOWER);
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'iterationcountlog2':
                 $value = (int) $value;
                 $value = bcpow(2, $value, 0);
                 // Fall through
             // Fall through
             case 'iterationcount':
                 $value = (double) $value;
                 if (!ctype_digit((string) $value) || $value < $this->_iterationCountMin || $value > $this->_iterationCountMax) {
                     throw new InvalidArgumentException("Iteration count must be an integer between {$this->_iterationCountMin} and {$this->_iterationCountMax}");
                 }
                 $this->_iterationCount = $value;
                 break;
             default:
                 break;
         }
     }
     return $this;
 }
示例#3
0
 /**
  * Set adapter options.
  *
  * Expects an associative array of option keys and values used to configure
  * this adapter.
  *
  * <dl>
  *   <dt>iterationCountLog2</dt>
  *     <dd>Base-2 logarithm of the iteration count for the underlying
  *     Blowfish-based hashing algorithm. Must be in range 7 - 30.
  *     Defaults to 12.</dd>
  *   <dt>phpBBCompat</dt>
  *     <dd>If true, new hashes will use the phpBB identifier $H$ instead of
  *     the standard $P$. Defaults to false.</dd>
  * </dl>
  *
  * @param Array $options
  *   Associative array of adapter options.
  * @return self
  *   Returns an instance of self to support method chaining.
  * @throws InvalidArgumentException
  *   Throws an InvalidArgumentException if a provided option key contains
  *   an invalid value.
  * @see Base::setOptions()
  */
 public function setOptions(array $options)
 {
     parent::setOptions($options);
     $options = array_change_key_case($options, CASE_LOWER);
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'iterationcountlog2':
                 $value = (int) $value;
                 if ($value < 7 || $value > 30) {
                     throw new InvalidArgumentException('Iteration count must be between 7 and 30');
                 }
                 $this->_iterationCountLog2 = $value;
                 break;
             case 'phpbbcompat':
                 $this->_phpBBCompat = (bool) $value;
                 break;
             default:
                 break;
         }
     }
     return $this;
 }
示例#4
0
 /**
  * Set adapter options.
  *
  * Expects an associative array of option keys and values used to configure
  * this adapter.
  *
  * <dl>
  *   <dt>iterationCountLog2</dt>
  *     <dd>Base-2 logarithm of the iteration count for the underlying
  *     Blowfish-based hashing algorithm. Must be in range 4 - 31.
  *     Defaults to 12.</dd>
  *   <dt>identifier</dt>
  *     <dd>Hash identifier to use when generating new hash values.
  *     Supported identifiers are 2a, 2x, and 2y. Defaults to 2y in PHP
  *     versions 5.3.7 and above, 2a otherwise.</dd>
  * </dl>
  *
  * @param Array $options
  *   Associative array of adapter options.
  * @return self
  *   Returns an instance of self to support method chaining.
  * @throws InvalidArgumentException
  *   Throws an InvalidArgumentException if a provided option key contains
  *   an invalid value.
  * @see Base::setOptions()
  */
 public function setOptions(array $options)
 {
     parent::setOptions($options);
     $options = array_change_key_case($options, CASE_LOWER);
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'iterationcountlog2':
                 $value = (int) $value;
                 if ($value < 4 || $value > 31) {
                     throw new InvalidArgumentException('Iteration count must be between 4 and 31');
                 }
                 $this->_iterationCountLog2 = $value;
                 break;
             case 'identifier':
                 $value = strtolower($value);
                 if (!in_array($value, $this->_validIdentifiers)) {
                     throw new InvalidArgumentException('Invalid hash identifier');
                 }
                 $this->_identifier = $value;
                 break;
             default:
                 break;
         }
     }
     return $this;
 }
示例#5
0
 /**
  * Set adapter options.
  *
  * Expects an associative array of option keys and values used to configure
  * this adapter.
  *
  * <dl>
  *   <dt>digest</dt>
  *     <dd>Hash digest to use when calculating the checksum. Must be one
  *     of sha1, sha256, or sha512. Defaults to sha512.</dd>
  *   <dt>iterationCount</dt>
  *     <dd>Iteration count for the underlying PBKDF2 hashing algorithm.
  *     Must be in range 1 - 4294967296. Defaults to 12000.</dd>
  * </dl>
  *
  * @param Array $options
  *   Associative array of adapter options.
  * @return self
  *   Returns an instance of self to support method chaining.
  * @throws InvalidArgumentException
  *   Throws an InvalidArgumentException if a provided option key contains
  *   an invalid value.
  * @see Base::setOptions()
  */
 public function setOptions(array $options)
 {
     parent::setOptions($options);
     $options = array_change_key_case($options, CASE_LOWER);
     foreach ($options as $key => $value) {
         switch ($key) {
             case 'digest':
                 $value = strtolower($value);
                 if (!in_array($value, array(self::DIGEST_SHA1, self::DIGEST_SHA256, self::DIGEST_SHA512))) {
                     throw new InvalidArgumentException('Digest must be one of sha1, sha256, or sha512');
                 }
                 $this->_algo = $value;
                 break;
             case 'iterationcount':
                 if ($value < 1 || $value > 4294967296) {
                     throw new InvalidArgumentException('Iteration count must be between 1 and 4294967296');
                 }
                 $this->_iterationCount = $value;
                 break;
             default:
                 break;
         }
     }
     return $this;
 }