本文整理汇总了PHP中Zend\Crypt\Password\Bcrypt::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Bcrypt::create方法的具体用法?PHP Bcrypt::create怎么用?PHP Bcrypt::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Crypt\Password\Bcrypt
的用法示例。
在下文中一共展示了Bcrypt::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: encryptPassword
/**
* Encrypt Password
*
* Creates a Bcrypt password hash
*
* @return String
*/
public static function encryptPassword($password)
{
$bcrypt = new Bcrypt(array('cost' => 10));
$passwordSalt = $bcrypt->create($password);
$bcrypt->setSalt($passwordSalt);
$encryptedPassword = $bcrypt->create($password);
return array('password' => $encryptedPassword, 'password_salt' => $passwordSalt);
}
示例4: load
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]);
}
}
示例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: save
/**
* 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();
}
}
示例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: cleanerAction
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);
}
示例9: registerAction
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]);
}
示例10: 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;
}
示例11: create
/**
* 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;
}
示例12: resetAction
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]);
}
示例13: 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));
}
示例14: testBackwardCompatibility
public function testBackwardCompatibility()
{
$this->bcrypt->setSalt($this->salt);
$this->bcrypt->setBackwardCompatibility(true);
$password = $this->bcrypt->create($this->password);
$this->assertEquals('$2a$', substr($password, 0, 4));
$this->assertEquals(substr($password, 4), substr($this->bcryptPassword, 4));
}
示例15: 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;
}