Exemple #1
0
 /**
  * Set an option for the instance
  *
  * @param string $option The option to set
  * @param mixed  $value  The value to set the option to
  *
  * @return $this
  */
 public function setOption($option, $value)
 {
     if ($option == 'kdf') {
         if (!$value instanceof \PasswordLib\Key\Derivation\PBKDF) {
             $factory = new KeyFactory();
             $value = $factory->getPBKDFFromSignature($value);
         }
     }
     $this->options[$option] = $value;
     return $this;
 }
Exemple #2
0
 /**
  * Load an instance of the class based upon the supplied hash
  *
  * @param string $hash The hash to load from
  *
  * @return Password the created instance
  * @throws InvalidArgumentException if the hash wasn't created here
  */
 public static function loadFromHash($hash)
 {
     if (!static::detect($hash)) {
         throw new \InvalidArgumentException('Hash Not Created Here');
     }
     $parts = explode('$', $hash);
     if (count($parts) != 7) {
         throw new \InvalidArgumentException('Hash Not Created Here');
     }
     $signature = $parts[2];
     $factory = new KeyFactory();
     $hash = $factory->getPBKDFFromSignature($signature);
     $iterations = $parts[3];
     $size = $parts[4];
     return new static($hash, $size, $iterations);
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testGetPBKDFFail()
 {
     $factory = new Factory();
     $factory->getPBKDF('someGibberish');
 }