我是试着做个人资料更新页面,被人可以改变个人资料的细节。他们需要密码来更新个人资料。
我正在使用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模块中加密密码?提前谢谢。
发布于 2015-04-07 11:51:05
Bcrypt不像MD5每次创建相同的字符串。如果要检查bcrypted密码是否有效,可以使用:
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$bcrypt->verify('isThisCorrect?', $userPasswordFromDB)https://stackoverflow.com/questions/29490366
复制相似问题