php Zend-Crypt-Password-Bcrypt类(方法)实例源码

下面列出了php Zend-Crypt-Password-Bcrypt 类(方法)源码代码实例,从而了解它的用法。

作者:juic3pow3r    项目:LdcUserProfil   
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);
 }

作者:spoore    项目:hangma   
public function registerAction()
 {
     $request = $this->getRequest();
     $form = new UserForm();
     $userNameConflict = false;
     if ($request->isPost()) {
         // check if the form is valid
         $form->setData($request->getPost());
         $form->setInputFilter(new UserInputFilter());
         if ($form->isValid()) {
             $data = $form->getData();
             $userRepo = $this->getObjectManager()->getRepository(User::class);
             $userNameConflict = $userRepo->findOneBy(['userName' => $data['username']]) instanceof User;
             if ($userNameConflict) {
                 $form->get('username')->setValue('');
             } else {
                 // if the requested username is not taken yet, create the password and redirect the user to the login
                 $user = new User();
                 $user->setEmail($data['email']);
                 $user->setUserName($data['username']);
                 $bcrypt = new Bcrypt();
                 $password = $bcrypt->create($data['password']);
                 $user->setPassword($password);
                 $this->getObjectManager()->persist($user);
                 $this->getObjectManager()->flush();
                 return $this->redirect()->toRoute('application/user', ['action' => 'login']);
             }
         }
     }
     return new ViewModel(['form' => $form, 'userNameConflict' => $userNameConflict]);
 }

作者:rodrigogk8    项目:djm   
/**
  *  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;
 }

作者:CPDeutschlan    项目:zf2-api-clien   
/**
  * This method inspects the request and routes the data
  * to the correct method
  *
  * @return void
  */
 public function create($unfilteredData)
 {
     $usersTable = $this->getUsersTable();
     $filters = $usersTable->getInputFilter();
     $filters->setData($unfilteredData);
     if ($filters->isValid()) {
         $data = $filters->getValues();
         $avatarContent = array_key_exists('avatar', $unfilteredData) ? $unfilteredData['avatar'] : NULL;
         $bcrypt = new Bcrypt();
         $data['password'] = $bcrypt->create($data['password']);
         if ($usersTable->create($data)) {
             $user = $usersTable->getByUsername($data['username']);
             if (!empty($avatarContent)) {
                 $userImagesTable = $this->getUserImagesTable();
                 $filename = sprintf('public/images/%s.png', sha1(uniqid(time(), TRUE)));
                 $content = base64_decode($avatarContent);
                 $image = imagecreatefromstring($content);
                 if (imagepng($image, $filename) === TRUE) {
                     $userImagesTable->create($user['id'], basename($filename));
                 }
                 imagedestroy($image);
                 $image = $userImagesTable->getByFilename(basename($filename));
                 $usersTable->updateAvatar($image['id'], $user['id']);
             }
             Mailer::sendWelcomeEmail($user['email'], $user['name']);
             $result = new JsonModel(array('result' => true));
         } else {
             $result = new JsonModel(array('result' => false));
         }
     } else {
         $result = new JsonModel(array('result' => false, 'errors' => $filters->getMessages()));
     }
     return $result;
 }

作者:i-xpert    项目:RollnAp   
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();
 }

作者:EngrHaiderAl    项目:movein-servi   
/**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed
  */
 public function authenticate()
 {
     if (empty($this->_username) || empty($this->_password)) {
         // throw new \Zend\Authentication\Adapter\Exception();
     }
     if (is_null($this->_dm)) {
         throw new \Exception('Document Manager is null');
     }
     $query = $this->_dm->createQueryBuilder('MoveIn4User\\Document\\UserDocument');
     $query->field('userName')->equals((string) $this->_username);
     // $query->field ( 'password' )->equals ((string) $this->_password );
     $query->field('active')->equals(true);
     $query->field('deleted')->equals(false);
     $users = $query->getQuery()->execute();
     if (count($users) === 0) {
         return new Result(Result::FAILURE_CREDENTIAL_INVALID, array());
     } else {
         foreach ($users as $user) {
             $bcrypt = new Bcrypt();
             if ($bcrypt->verify((string) $this->_password, $user->getPassword()) and $user->getInstance()->getDeleted() === false) {
                 return new Result(Result::SUCCESS, array('username' => $user->getUserName(), 'firstName' => $user->getFirstName(), 'surname' => $user->getSurname(), 'defaultLanguage' => $user->getInstance()->getDefaultLanguage(), 'id' => $user->getId()));
             }
             return new Result(Result::FAILURE_CREDENTIAL_INVALID, array());
         }
     }
 }

作者:kalel    项目:inventor   
public function authenticate($username, $password)
 {
     $callback = function ($password, $hash) {
         $bcrypt = new Bcrypt();
         return $bcrypt->verify($hash, $password);
     };
     $authenticationService = new AuthenticationService();
     $callbackCheckAdapter = new CallbackCheckAdapter($this->dbAdapter, "users", 'username', 'password', $callback);
     $callbackCheckAdapter->setIdentity($username)->setCredential($password);
     $authenticationService->setAdapter($callbackCheckAdapter);
     $authResult = $authenticationService->authenticate();
     if ($authResult->isValid()) {
         $userObject = $callbackCheckAdapter->getResultRowObject();
         $authenticationService->getStorage()->write($userObject);
         if ($userObject->status == 0) {
             $authenticationService->clearIdentity();
             $this->setCode(-5);
             return false;
         } else {
             return true;
         }
     } else {
         $this->setCode($authResult->getCode());
         return false;
     }
 }

作者:JohannesGirar    项目:WebCashRegister-zf   
public function indexAction()
 {
     if (@$_SESSION['user']['Logged'] == 1 || @$_SESSION['user']['Level'] == 1) {
         return $this->redirect()->toRoute('application');
     }
     $userContainer = new Container('user');
     $userContainer->Logged;
     $userContainer->Level;
     $userContainer->Nom;
     $userContainer->Prenom;
     $form = new AuthForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $bcrypt = new Bcrypt();
         $User = new User();
         $User->user_login = $request->getPost('login');
         $User->user_password = $request->getPost('motdepasse');
         $UserO = $this->getUserTable()->getVerificationAuth($User->user_login);
         if ($UserO == true) {
             $securepass = $UserO->user_password;
             if ($bcrypt->verify($User->user_password, $securepass)) {
                 $userContainer->Nom = $UserO->user_nom;
                 $userContainer->Prenom = $UserO->user_prenom;
                 $userContainer->Userid = $UserO->user_id;
                 $userContainer->Logged = 1;
                 $userContainer->Level = $UserO->user_droit;
                 return $this->redirect()->toRoute('application');
             } else {
                 return array('form' => $form, 'erreur' => 'Mauvais Login ou Mauvais Mot de passe');
             }
         }
     }
     return array('form' => $form);
 }

作者:oleglavri    项目:test-task-yawar   
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);
 }

作者:aqili    项目:i-experts-apigility-oauth2-doctrin   
public function load(ObjectManager $manager)
 {
     $bcrypt = new Bcrypt();
     $clientSecret = $bcrypt->create('123456');
     $grantTypes = array('mobile' => array('password', 'implicit', 'refresh_token'), 'custom' => array('client_credentials', 'implicit', 'refresh_token'));
     $redirectUri = '/oauth/receivecode';
     $clientCredentialScope = array($this->getReference('scope0'), $this->getReference('scope1'), $this->getReference('scope2'));
     $clientData = array(array('user' => null, 'secret' => $clientSecret, 'client_id' => 'mobile', 'grant_type' => $grantTypes['mobile']), array('user' => $this->getReference('user0'), 'secret' => $clientSecret, 'client_id' => '55f94d5ee7707', 'grant_type' => $grantTypes['custom'], 'scope' => $clientCredentialScope), array('user' => $this->getReference('user1'), 'secret' => $clientSecret, 'client_id' => '55f94d92d97e5', 'grant_type' => $grantTypes['custom'], 'scope' => $clientCredentialScope));
     foreach ($clientData as $key => $data) {
         $client[$key] = new Client();
         $client[$key]->setUser($data['user']);
         $client[$key]->setSecret($data['secret']);
         $client[$key]->setClientId($data['client_id']);
         $client[$key]->setRedirectUri($redirectUri);
         $client[$key]->setGrantType($data['grant_type']);
         if (isset($data['scope'])) {
             foreach ($data['scope'] as $scope) {
                 $client[$key]->addScope($scope);
                 $scope->addClient($client[$key]);
                 $manager->persist($scope);
             }
         }
         $manager->persist($client[$key]);
     }
     $manager->flush();
     foreach ($clientData as $key => $data) {
         $this->addReference('client' . $key, $client[$key]);
     }
 }

作者:hicharlesroch    项目:orcamento   
/**
  * Function that saves a new User
  * @param                 array $data
  * @return                Orcamentos\Model\User $user
  */
 public function save($data)
 {
     $data = json_decode($data);
     if (!isset($data->name) || !isset($data->password) || !isset($data->email) || !isset($data->companyId)) {
         throw new Exception("Invalid Parameters", 1);
     }
     $user = $this->getUser($data);
     $user->setName($data->name);
     $user->setEmail($data->email);
     $password = $user->getPassword();
     if (!isset($password) || $password != $data->password) {
         $bcrypt = new Bcrypt();
         $password = $bcrypt->create($data->password);
     }
     $user->setPassword($password);
     $admin = false;
     if (isset($data->admin)) {
         $admin = true;
     }
     $user->setAdmin($admin);
     $company = $this->em->getRepository('Orcamentos\\Model\\Company')->find($data->companyId);
     if (!isset($company)) {
         throw new Exception("Empresa não encontrada", 1);
     }
     $user->setCompany($company);
     try {
         $this->em->persist($user);
         $this->em->flush();
         return $user;
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }

作者:duluma    项目:big   
public function setPasswordBcrypt(Bcrypt $passwordBcrypt)
 {
     $passwordBcrypt->setSalt(self::BCRYPT_SALT);
     $passwordBcrypt->setCost(self::BCRYPT_COST);
     $this->passwordBcrypt = $passwordBcrypt;
     return $this;
 }

作者:Indigo133    项目:c4   
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();
 }

作者:jom    项目:TheNightsWatch   
public function resetAction()
 {
     $this->updateLayoutWithIdentity();
     $form = new ResetForm();
     $errors = [];
     if ($this->getRequest()->isPost()) {
         $form->setData($this->getRequest()->getPost());
         if ($form->isValid()) {
             try {
                 $minecraft = new MinecraftAPI($form->get('username')->getValue(), $form->get('mojangPassword')->getValue());
                 $user = $this->getEntityManager()->getRepository('NightsWatch\\Entity\\User')->findOneBy(['username' => $minecraft->username]);
                 if (!$user) {
                     $errors[] = 'No Such User';
                 } else {
                     $bcrypt = new Bcrypt();
                     $user->password = $bcrypt->create($form->get('password')->getValue());
                     $this->getEntityManager()->persist($user);
                     $this->getEntityManager()->flush();
                     $this->getAuthenticationService()->authenticate(new ForceAdapter($user->id));
                     $this->updateLayoutWithIdentity();
                     return new ViewModel(['done' => true]);
                 }
             } catch (\RuntimeException $e) {
                 $errors[] = 'Problem querying the API';
             } catch (BadLoginException $e) {
                 $errors[] = 'Invalid username or Password';
             } catch (MigrationException $e) {
                 $errors[] = 'Your Minecraft account has been migrated to a Mojang account.  ' . 'Please enter your Mojang email and try again';
             } catch (BasicException $e) {
                 $errors[] = 'This is not a premium Minecraft Account';
             }
         }
     }
     return new ViewModel(['done' => false, 'errors' => $errors, 'form' => $form]);
 }

作者:gdpr    项目:gdpro-use   
public static function validate($user, $passwordGiven)
 {
     $passwordHash = $user->getPassword();
     $passwordBcrypt = new Bcrypt();
     $result = $passwordBcrypt->verify($passwordGiven, $passwordHash);
     return $result;
 }

作者:mrwomba    项目:test-etneter   
public function cleanerAction()
 {
     $form = new CleanerForm();
     $form->setAttribute('method', 'POST');
     $repo = array();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost();
         #test cipher
         $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes', 'hash' => 'sha512'));
         $blockCipher->setKey('DA$#3434fsa432dfef32327');
         $hash = 'f19f8bf56c4f61b6b2ca51e4cd5973faa5a165e4db6ad7aae0f065463ba2330fx2kZPSH5xCnLy48nVPWnprIh601be0H2Quh2o88oCws=';
         #\Zend\Debug\Debug::dump($blockCipher->decrypt($hash));
         #test bcrypt
         $bcrypt = new Bcrypt();
         $hash = $bcrypt->create('xxx');
         $hash = '$2y$10$HQORKaG/QUWk.wJGj9lPuOHLTrm11pRdSSBDP.L2JVrAkCid7W5O.';
         #get git data
         $pwd = $request->getPost()['pwd'];
         $hour = $request->getPost()['hour'];
         if ($bcrypt->verify($pwd, $hash) && is_numeric($hour)) {
             $this->getActionLogTable()->deleteOlderThan($hour);
             $result['message'] = 'OK';
         } else {
             $result['message'] = 'Error. Passwd or Hour are not valid.';
         }
     }
     $result['form'] = $form;
     return new ViewModel($result);
 }

作者:reli    项目:rcm-use   
/**
  * 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;
 }

作者:antaru    项目:mystra-pv   
/**
  * 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));
 }

作者:aapth    项目:taggerzz-ne   
/**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $options = $serviceLocator->get('zfcuser_module_options');
     $crypto = new Bcrypt();
     $crypto->setCost($options->getPasswordCost());
     return new Mapper\UserHydrator($crypto);
 }

作者:luiz15    项目:orcamento   
public function postLogin(Request $request, Application $app)
 {
     $data = $request->request->all();
     if (!isset($data['email']) || !isset($data['password'])) {
         $app['session']->getFlashBag()->add('message', 'Email e/ou senha inválidos!');
         return $app->redirect('/');
     }
     $user = $app['orm.em']->getRepository('Orcamentos\\Model\\User')->findOneBy(array('email' => $data['email']));
     if (!$user) {
         $app['session']->getFlashBag()->add('message', 'Usuário inválido!');
         return $app->redirect('/');
     }
     $bcrypt = new Bcrypt();
     $valid = $bcrypt->verify($data['password'], $user->getPassword());
     if (!$valid) {
         $app['session']->getFlashBag()->add('message', 'Email e/ou senha inválidos!');
         return $app->redirect('/');
     }
     $app['session']->set('email', $data['email']);
     $app['session']->set('isAdmin', $user->getAdmin());
     $app['session']->set('companyId', $user->getCompany()->getId());
     $app['session']->set('companyLogotype', $user->getCompany()->getLogotype());
     $app['session']->set('companyName', $user->getCompany()->getName());
     if ($user->getAdmin()) {
         return $app->redirect('/');
     }
     return $app->redirect('/project');
 }


问题


面经


文章

微信
公众号

扫码关注公众号