本文整理汇总了PHP中Zend\Crypt\Password\Bcrypt::setCost方法的典型用法代码示例。如果您正苦于以下问题:PHP Bcrypt::setCost方法的具体用法?PHP Bcrypt::setCost怎么用?PHP Bcrypt::setCost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Crypt\Password\Bcrypt
的用法示例。
在下文中一共展示了Bcrypt::setCost方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getBcrypt
/**
* @return Bcrypt
*/
public function getBcrypt()
{
if (null === $this->bcrypt) {
$this->bcrypt = new Bcrypt();
$this->bcrypt->setCost($this->bcryptCost);
}
return $this->bcrypt;
}
示例2: __construct
public function __construct(RestMapperInterface $userMapper, $config = [])
{
$this->userMapper = $userMapper;
$this->bcrypt = new Bcrypt();
if (isset($config['zf2-oauth']['storage_settings']['bcrypt_cost'])) {
$this->bcryptCost = (int) $config['zf2-oauth']['storage_settings']['bcrypt_cost'];
}
$this->bcrypt->setCost($this->bcryptCost);
}
示例3: createAction
/**
* Action pour la création.
*
* @return array
*/
public function createAction()
{
$oForm = new \Commun\Form\UsersForm();
//new \Commun\Form\UsersForm($this->getServiceLocator());
$oRequest = $this->getRequest();
$oFiltre = new \Commun\Filter\UsersFilter();
$oForm->setInputFilter($oFiltre->getInputFilter());
if ($oRequest->isPost()) {
$oEntite = new \Commun\Model\Users();
$aPost = $oRequest->getPost();
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$aPost['password'] = $bcrypt->create($aPost['password']);
$oForm->setData($aPost);
if ($oForm->isValid()) {
$oEntite->exchangeArray($oForm->getData());
$this->getTable()->insert($oEntite);
$this->flashMessenger()->addMessage($this->_getServTranslator()->translate("La users a été créé avec succès."), 'success');
return $this->redirect()->toRoute('backend-users-list');
} else {
$this->flashMessenger()->addMessage($this->_getServTranslator()->translate("Formulaire non valid."), 'error');
return $this->redirect()->toRoute('backend-users-create');
}
}
// Pour optimiser le rendu
$oViewModel = new ViewModel();
$oViewModel->setTemplate('backend/users/create');
return $oViewModel->setVariables(array('form' => $oForm));
}
示例4: createService
/**
* createService
*
* @param ServiceLocatorInterface $serviceLocator serviceLocator
*
* @return PasswordInterface
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$cfg = $serviceLocator->get('RcmUser\\User\\Config');
$encryptor = new Bcrypt();
$encryptor->setCost($cfg->get('Encryptor.passwordCost', 14));
return $encryptor;
}
示例5: addUser
public function addUser($data)
{
# get data
$email = isset($data['email']) ? $data['email'] : null;
$password = isset($data['password']) ? $data['password'] : null;
$role = isset($data['role']) ? $data['role'] : null;
# Bcrypt for password
if (!is_null($password)) {
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$password = $bcrypt->create($password);
}
# insert new personal data user
$arr = array('email' => $email, 'password' => $password);
$this->tableGateway->insert($arr);
# select current user id
$userId = $this->tableGateway->select(function (Select $select) use($email) {
$select->columns(array('user_id'))->where(array('email' => $email))->limit(1);
});
$userId = $userId->toArray();
# select id role
$userRoleId = $this->tableGateway2->select(function (Select $select) use($role) {
$select->columns(array('id'))->where(array('roleId' => $role))->limit(1);
});
$userRoleId = $userRoleId->toArray();
$arr = array('user_id' => $userId['0']['user_id'], 'role_id' => $userRoleId['0']['id']);
# insert role for new user
$this->tableGateway3->insert($arr);
}
示例6: createService
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$options = $serviceLocator->get('zfcuser_module_options');
$crypto = new Bcrypt();
$crypto->setCost($options->getPasswordCost());
return new Mapper\UserHydrator($crypto);
}
示例7: save
public function save($entity)
{
if (!isset($entity->zfcuser) || !$entity->zfcuser instanceof UserInterface) {
throw new \RuntimeException('Entity must implement ZfcUser\\Entity\\UserInterface');
}
// If the user specified a new password, hash it
$password = $entity->zfcuser->getPassword();
if (!empty($password)) {
$hydrator = $this->getFieldset()->getHydrator();
if (method_exists($hydrator, 'getCryptoService')) {
// ZfcUser dev-master
$hash = $this->getFieldset()->getHydrator()->getCryptoService()->create($password);
} else {
$bcrypt = new Bcrypt();
$bcrypt->setCost($this->getUserService()->getOptions()->getPasswordCost());
$hash = $bcrypt->create($password);
}
$entity->zfcuser->setPassword($hash);
// Clear out the password values now that we don't need them again
$this->getFieldset()->get('password')->setValue('');
$this->getFieldset()->get('passwordVerify')->setValue('');
}
// Reload the actual user entity and transfer changes to it
// (necessary for ZfcUserDoctrineORM to work, as $entity->zfcuser is disconnected)
$userobj = $this->getUserService()->getUserMapper()->findById($entity->zfcuser->getId());
$this->transferChangesToExistingEntity($entity->zfcuser, $userobj);
// Stash the new entity back in the original's place so that later
// extensions can use it in Doctrine associations safely
$entity->zfcuser = $userobj;
return $this->getUserService()->getUserMapper()->update($userobj);
}
示例8: load
public function load(ObjectManager $manager)
{
$userFlop = false;
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$scope1 = new OAuth2Scope();
$scope1->setScope('read');
$scope1->setIsDefault(true);
$manager->persist($scope1);
$scope2 = new OAuth2Scope();
$scope2->setScope('update');
$scope2->setIsDefault(false);
$manager->persist($scope2);
$scope3 = new OAuth2Scope();
$scope3->setScope('delete');
$scope3->setIsDefault(false);
$manager->persist($scope3);
$scope4 = new OAuth2Scope();
$scope4->setScope('create');
$scope4->setIsDefault(false);
$manager->persist($scope4);
$user2 = new Entity\User();
$user2->setUsername('user2');
$user2->setPassword($bcrypt->create('user2password'));
$user2->setEmail('tom.h.anderson@gmail.com');
$user2->setDisplayName('Tom Anderson');
$manager->persist($user2);
$client2 = new OAuth2Client();
$client2->setClientId('readonly');
$client2->setSecret($bcrypt->create('readonly_password'));
$client2->setGrantType(array('client_credentials', 'refresh_token'));
$client2->setUser($user2);
$client2->addScope($scope1);
$scope1->addClient($client2);
$manager->persist($client2);
// Artists
$artist = new Entity\Artist();
$artist->setName('Grateful Dead');
$manager->persist($artist);
$albums = array('The Grateful Dead', 'Anthem of the Sun', 'Aoxomoxoa', 'Live/Dead', 'Workingman\'s Dead', 'American Beauty');
foreach ($albums as $name) {
$album = new Entity\Album();
$album->setArtist($artist);
$album->setName($name);
$manager->persist($album);
$userAlbum = new Entity\UserAlbum();
$userAlbum->setAlbum($album);
if ($userFlop = !$userFlop) {
# $userAlbum->setUser($user1);
} else {
$userAlbum->setUser($user2);
}
$userAlbum->setDescription("Description for {$name}");
$manager->persist($userAlbum);
}
$loop = new Entity\TestLoop();
$loop->setParentLoop($loop);
$manager->persist($loop);
$manager->flush();
}
示例9: hashPassword
/**
* Retorna hash Bcrypt del password del usuario
*/
public static function hashPassword($password, $cost)
{
$bcrypt = new Bcrypt();
$bcrypt->setCost($cost);
$securePass = $bcrypt->create($password);
return $securePass;
}
示例10: load
public function load(ObjectManager $manager)
{
$bcrypt = new Bcrypt();
$bcrypt->setCost(16);
$admin = new \User\Entity\User();
$admin->setUsername('admin');
$admin->setDisplayName('Admin');
$admin->setEmail('admin@c4d.de');
$admin->setState(1);
$admin->setPassword($bcrypt->create('password'));
$admin->addRole($this->getReference('role_admin'));
$userOne = new \User\Entity\User();
$userOne->setUsername('User A');
$userOne->setDisplayName('Anton');
$userOne->setEmail('usera@c4d.de');
$userOne->setState(1);
$userOne->setPassword($bcrypt->create('password'));
$userOne->addRole($this->getReference('role_user'));
$userTwo = new \User\Entity\User();
$userTwo->setUsername('User B');
$userTwo->setDisplayName('Berty');
$userTwo->setEmail('userb@c4d.de');
$userTwo->setState(1);
$userTwo->setPassword($bcrypt->create('password'));
$userTwo->addRole($this->getReference('role_user'));
$manager->persist($admin);
$manager->persist($userOne);
$manager->persist($userTwo);
$this->addReference('user_admin', $admin);
$this->addReference('user_a', $userOne);
$this->addReference('user_b', $userTwo);
$manager->flush();
}
示例11: setPasswordBcrypt
public function setPasswordBcrypt(Bcrypt $passwordBcrypt)
{
$passwordBcrypt->setSalt(self::BCRYPT_SALT);
$passwordBcrypt->setCost(self::BCRYPT_COST);
$this->passwordBcrypt = $passwordBcrypt;
return $this;
}
示例12: hashPassword
public function hashPassword($password)
{
$zfUserOption = $this->getServiceManager()->get('zfcuser_module_options');
$bcrypt = new Bcrypt();
$bcrypt->setCost($zfUserOption->getPasswordCost());
$pass = $bcrypt->create($password);
return $pass;
}
示例13: authenticate
public function authenticate(AuthEvent $e)
{
if ($this->isSatisfied()) {
$storage = $this->getStorage()->read();
$e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
return;
}
$identity = $e->getRequest()->getPost()->get('identity');
$credential = $e->getRequest()->getPost()->get('credential');
$credential = $this->preProcessCredential($credential);
$userObject = null;
// Cycle through the configured identity sources and test each
$fields = $this->getOptions()->getAuthIdentityFields();
while (!is_object($userObject) && count($fields) > 0) {
$mode = array_shift($fields);
switch ($mode) {
case 'username':
$userObject = $this->getMapper()->findByUsername($identity);
break;
case 'email':
$userObject = $this->getMapper()->findByEmail($identity);
break;
}
}
if (!$userObject) {
$e->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.'));
$this->setSatisfied(false);
return false;
}
if ($this->getOptions()->getEnableUserState()) {
// Don't allow user to login if state is not in allowed list
if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) {
$e->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.'));
$this->setSatisfied(false);
return false;
}
}
$bcrypt = new Bcrypt();
$bcrypt->setCost($this->getOptions()->getPasswordCost());
if (!$bcrypt->verify($credential, $userObject->getPassword())) {
// Password does not match
$e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.'));
$this->setSatisfied(false);
return false;
}
// regen the id
$session = new SessionContainer($this->getStorage()->getNameSpace());
$session->getManager()->regenerateId();
// Success!
$e->setIdentity($userObject->getId());
// Update user's password hash if the cost parameter has changed
$this->updateUserPasswordHash($userObject, $credential, $bcrypt);
$this->setSatisfied(true);
$storage = $this->getStorage()->read();
$storage['identity'] = $e->getIdentity();
$this->getStorage()->write($storage);
$e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
}
示例14: resetPassword
public function resetPassword($uuid, $password)
{
$userId = $this->userUuidMapper->getUuid($uuid)[0]['user_id'];
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
$pass = $bcrypt->create($password);
$this->userMapper->updatePassword($userId, $pass);
$uuid = $this->userUuidMapper->deleteUuid($uuid);
}
示例15: verify
public function verify($password, $hash)
{
if ($this->method == 'md5') {
return $hash == md5($this->salt . $password);
} elseif ($this->method == 'sha1') {
return $hash == sha1($this->salt . $password);
} elseif ($this->method == 'bcrypt') {
$bcrypt = new Bcrypt();
$bcrypt->setCost(14);
return $bcrypt->verify($password, $hash);
}
}