首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将用户插入的密码转换为zfcuser加密密码

将用户插入的密码转换为zfcuser加密密码
EN

Stack Overflow用户
提问于 2015-04-07 11:20:40
回答 1查看 619关注 0票数 0

我是试着做个人资料更新页面,被人可以改变个人资料的细节。他们需要密码来更新个人资料。

我正在使用zfcuser模块进行登录和注册.我不知道zfcuser使用哪种加密技术。

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

比如,如果user_inserted_password==encrypted_password_in_database然后更新配置文件。

我也试过这段代码

代码语言:javascript
复制
$bcrypt = new Bcrypt;
$bcrypt->setCost(14);
$pass = $bcrypt->create($newpass);

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

代码语言:javascript
复制
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模块中加密密码?提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-07 11:51:05

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

代码语言:javascript
复制
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$bcrypt->verify('isThisCorrect?', $userPasswordFromDB)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29490366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档