将用户输入的密码转换为 zfcuser 加密后的密码

convert user inserted password into zfcuser encrypted password

我正在尝试制作个人资料更新页面,人们可以更改个人资料详细信息。他们需要密码才能更新个人资料。

我正在使用 zfcuser 模块进行登录和注册。 我不知道 zfcuser.

使用了哪种加密技术

现在我需要将 zfcuser 加密的密码与用户在配置文件更新时输入的密码进行比较。

喜欢,如果 user_inserted_password==encrypted_password_in_database 则更新个人资料。

我也试过这个代码

$bcrypt = new Bcrypt;
$bcrypt->setCost(14);
$pass = $bcrypt->create($newpass);

但与数据库中的加密密码不匹配。 最后我用了这段代码,

use ZfcUser\Options\PasswordOptionsInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use ZfcUser\Mapper\UserInterface as UserMapperInterface;
use ZfcBase\EventManager\EventProvider;
use GoalioForgotPassword\Options\ForgotOptionsInterface;

use Zend\Crypt\Password\Bcrypt;

class ReservationsController extends AbstractActionController
{
 protected $zfcUserOptions;
 public function indexAction()
 {
  $bcrypt = new Bcrypt;
  $bcrypt->setCost($this->getZfcUserOptions()->getPasswordCost());
  $pass = $bcrypt->create("test");
  echo $pass; exit;
 }

 public function getZfcUserOptions()
 {
    if (!$this->zfcUserOptions instanceof PasswordOptionsInterface) {
        $this->setZfcUserOptions($this->getServiceManager()->get('zfcuser_module_options'));
    }
    return $this->zfcUserOptions;
 }
}

但是出现这个错误。

Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for getServiceManager

有朋友知道吗?如何在zend2 zfcuser 模块中加密密码? 提前致谢。

Bcrypt 不像 MD5 那样每次都创建相同的字符串。如果你想检查一个bcrypted密码是否有效,你可以使用:

$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$bcrypt->verify('isThisCorrect?', $userPasswordFromDB)