/** * (non-PHPdoc) * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword() */ public static function parsePassword(Attribute $password_hash) { $password = new Password(); $password->setAttribute($password_hash); $password->setHash($password_hash->get()); $password->setId('default'); /*if(preg_match('#^[0-9A-F]$#',$password_hash->get())===1) { $password->setMasterPassword(true); }elseif(preg_match('#^[0-9a-f]$#',$password_hash->get())===1) { $password->setMasterPassword(false); }*/ $password->setEncoder(NtEncoder::class); return $password; }
/** * (non-PHPdoc) * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword() */ public static function parsePassword(Attribute $password_hash) { $password = new Password(); $password->setAttribute($password_hash); $matches = null; $found = preg_match('#^{crypt}\\$\\d\\$(rounds=\\d+\\$)?([0-9a-zA-Z_-]+)?(=|\\+)[0-9a-zA-Z_-]+\\$[^\\$]*$#', $password_hash->get(), $matches); if ($found === 1) { $password->setId($matches[2]); $password->setMasterPassword($matches[3] === '+'); } else { return null; } $password->setEncoder(CryptEncoder::class); return $password; }
/** * * @param Password $password * @return \Cloud\LdapBundle\Entity\Service */ public function addPassword(Password $password) { //@TODO update to new schema if ($password->getEncoder() === $this->getEncoder()) { $attr = $this->getAttributes()->get('sambalmpassword'); $attr->set($password->getAttribute()->get()); $password->setAttribute($attr); $this->password = $password; return $this; } if ($password->getPasswordPlain() === null) { throw new \InvalidArgumentException("can't store false encoded password"); } $password->setAttribute($this->getAttributes()->get('sambalmpassword')); call_user_func($this->getEncoder() . '::encodePassword', $password); return $this; }