當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EncryptorInterface::isValidHash方法代碼示例

本文整理匯總了PHP中Magento\Framework\Encryption\EncryptorInterface::isValidHash方法的典型用法代碼示例。如果您正苦於以下問題:PHP EncryptorInterface::isValidHash方法的具體用法?PHP EncryptorInterface::isValidHash怎麽用?PHP EncryptorInterface::isValidHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Framework\Encryption\EncryptorInterface的用法示例。


在下文中一共展示了EncryptorInterface::isValidHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Harden admin password change.
  *
  * New password must be minimum 7 chars length and include alphanumeric characters
  * The password is compared to at least last 4 previous passwords to prevent setting them again
  *
  * @param EventObserver $observer
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function execute(EventObserver $observer)
 {
     /* @var $user \Magento\User\Model\User */
     $user = $observer->getEvent()->getObject();
     if ($user->getNewPassword()) {
         $password = $user->getNewPassword();
     } else {
         $password = $user->getPassword();
     }
     if ($password && !$user->getForceNewPassword() && $user->getId()) {
         if ($this->encryptor->isValidHash($password, $user->getOrigData('password'))) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, but this password has already been used. Please create another.'));
         }
         // check whether password was used before
         $passwordHash = $this->encryptor->getHash($password, false);
         foreach ($this->userResource->getOldPasswords($user) as $oldPasswordHash) {
             if ($passwordHash === $oldPasswordHash) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, but this password has already been used. Please create another.'));
             }
         }
     }
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:32,代碼來源:CheckAdminPasswordChangeObserver.php

示例2: validatePasswordChange

 /**
  * Make sure admin password was changed.
  *
  * New password is compared to at least 4 previous passwords to prevent setting them again
  *
  * @return bool|string[]
  */
 protected function validatePasswordChange()
 {
     $password = $this->getPassword();
     if ($password && !$this->getForceNewPassword() && $this->getId()) {
         $errorMessage = __('Sorry, but this password has already been used. Please create another.');
         // Check if password is equal to the current one
         if ($this->_encryptor->isValidHash($password, $this->getOrigData('password'))) {
             return [$errorMessage];
         }
         // Check whether password was used before
         $passwordHash = $this->_encryptor->getHash($password, false);
         foreach ($this->getResource()->getOldPasswords($this) as $oldPasswordHash) {
             if ($passwordHash === $oldPasswordHash) {
                 return [$errorMessage];
             }
         }
     }
     return true;
 }
開發者ID:vv-team,項目名稱:foodo,代碼行數:26,代碼來源:User.php


注:本文中的Magento\Framework\Encryption\EncryptorInterface::isValidHash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。