Example #1
0
 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->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('*****@*****.**');
     $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('*****@*****.**');
     $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();
 }
Example #2
0
 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('*****@*****.**');
     $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();
 }
Example #3
0
 /**
  * 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);
 }
 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]);
     }
 }
Example #5
0
 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);
 }
Example #6
0
 /**
  * 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();
     }
 }
 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);
 }
 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);
 }
Example #9
0
 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]);
 }
Example #10
0
 /**
  *  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;
 }
 /**
  * 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;
 }
Example #12
0
 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]);
 }
Example #13
0
 /**
  * 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));
 }
Example #14
0
 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));
 }
Example #15
0
 public function hashPassword($password)
 {
     $zfUserOption = $this->getServiceManager()->get('zfcuser_module_options');
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($zfUserOption->getPasswordCost());
     $pass = $bcrypt->create($password);
     return $pass;
 }
 public function processRegistration($data)
 {
     $bcrypt = new Bcrypt();
     $data->password = $bcrypt->create($data->password);
     $registerEntity = new RegistrationEntity();
     $this->getMapper()->getHydrator()->hydrate((array) $data, $registerEntity);
     return $this->getMapper()->insert($registerEntity);
 }
Example #17
0
 public function create($password)
 {
     if (empty($this->salt)) {
         $salt = $this->salt = Rand::getBytes(self::MIN_SALT_SIZE);
     } else {
         $salt = $this->salt;
     }
     return parent::create($password);
 }
Example #18
0
 /**
  * Set password
  *
  * @param string $password
  * @return User
  */
 public function setPassword($password)
 {
     if ($password) {
         $bcrypt = new Bcrypt();
         $password = $bcrypt->create($password);
     }
     $this->password = $password;
     return $this;
 }
Example #19
0
 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);
 }
 public function update($data, $id)
 {
     $hydrator = new ObjectProperty();
     $data = $hydrator->extract($data);
     if (!empty($data['password'])) {
         $bcrypt = new Bcrypt();
         $data['password'] = $bcrypt->create($data['password']);
     }
     return $this->tableGateway->update($data, $id);
 }
 public function create($username, $password, $fullname)
 {
     if ($this->byUsername($username)) {
         throw new DomainException(sprintf('Username "%s" already exists', $username), 409);
     }
     $crypt = new Bcrypt();
     $user = array('user_id' => (string) Uuid::uuid4(), 'username' => $username, 'password' => $crypt->create($password), 'name' => $fullname);
     $this->table->insert($user);
     return new $this->entityClass($user);
 }
Example #22
0
 public function load(ObjectManager $manager)
 {
     $userFlop = false;
     $bcrypt = new Bcrypt();
     $bcrypt->setCost(14);
     $scope1 = $manager->getRepository('ZF\\OAuth2\\Entity\\Scope')->findOneBy(array('scope' => 'read'));
     $scope2 = $manager->getRepository('ZF\\OAuth2\\Entity\\Scope')->findOneBy(array('scope' => 'update'));
     $scope3 = $manager->getRepository('ZF\\OAuth2\\Entity\\Scope')->findOneBy(array('scope' => 'delete'));
     $scope4 = $manager->getRepository('ZF\\OAuth2\\Entity\\Scope')->findOneBy(array('scope' => 'create'));
     $user1 = new Entity\User();
     $user1->setUsername('user1');
     $user1->setPassword($bcrypt->create('user1password'));
     $user1->setEmail('*****@*****.**');
     $user1->setDisplayName('Tom Anderson');
     $manager->persist($user1);
     $client1 = new OAuth2Client();
     $client1->setClientId('root');
     $client1->setSecret($bcrypt->create('root_password'));
     $client1->setGrantType(array('urn:ietf:params:oauth:grant-type:jwt-bearer', 'password', 'authorization_code', 'client_credentials', 'refresh_token'));
     $client1->setUser($user1);
     $client1->addScope($scope1);
     $client1->addScope($scope2);
     $client1->addScope($scope3);
     $client1->addScope($scope4);
     $scope1->addClient($client1);
     $scope2->addClient($client1);
     $scope3->addClient($client1);
     $scope4->addClient($client1);
     $manager->persist($client1);
     $jwt1 = new OAuth2Jwt();
     $jwt1->setSubject('user1');
     $jwt1->setPublicKey(file_get_contents(__DIR__ . '/../../../../../../media/pubkey.pem'));
     $jwt1->setClient($client1);
     $manager->persist($jwt1);
     $jti1 = new OAuth2Jti();
     $jti1->setSubject('user1');
     $jti1->setAudience('http://localhost:8083');
     $jti1->setExpires(new DateTime(' today +1 day'));
     $jti1->setJti('123456abcdef');
     $jti1->setClient($client1);
     $manager->persist($jti1);
     $manager->flush();
 }
Example #23
0
 public function testPasswordWith8bitCharacter()
 {
     $password = '******' . chr(128);
     $this->bcrypt->setSalt($this->salt);
     if (version_compare(PHP_VERSION, '5.3.7') >= 0) {
         $this->assertEquals('$2y$14$MTIzNDU2Nzg5MDEyMzQ1NexAbOIUHkG6Ra.TK9QxHOVUhDxOe4dkW', $this->bcrypt->create($password));
     } else {
         $this->setExpectedException('Zend\\Crypt\\Password\\Exception\\RuntimeException', 'The bcrypt implementation used by PHP can contains a security flaw ' . 'using password with 8-bit character. ' . 'We suggest to upgrade to PHP 5.3.7+ or use passwords with only 7-bit characters');
         $output = $this->bcrypt->create($password);
     }
 }
Example #24
0
 public function create($password)
 {
     if ($this->method == 'md5') {
         return md5($this->salt . $password);
     } elseif ($this->method == 'sha1') {
         return sha1($this->salt . $password);
     } elseif ($this->method == 'bcrypt') {
         $bcrypt = new Bcrypt();
         $bcrypt->setCost(14);
         return $bcrypt->create($password);
     }
 }
Example #25
0
 /**
  * Creates a new user.
  *
  * @param string $alias
  * @param string $status
  * @param string $email
  * @param string $pw
  * @param array $meta
  * @return User
  */
 public function create($alias, $status = 'placeholder', $email = null, $pw = null, array $meta = array())
 {
     if (!(is_string($alias) && strlen($alias) >= 3)) {
         throw new InvalidArgumentException('User name too short');
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost(6);
     $user = new User(array('alias' => $alias, 'status' => $status, 'email' => $email, 'pw' => $bcrypt->create($pw)), $meta);
     $this->save($user);
     $this->getEventManager()->trigger('create', $user);
     return $user;
 }
 public function exchangeArray($data)
 {
     $this->id = !empty($data['id']) ? $data['id'] : null;
     $this->email = !empty($data['email']) ? $data['email'] : null;
     if (!empty($data['nick']) && !empty($data['password']) && !empty($data['email']) && !empty($data['name']) && !empty($data['surname'])) {
         $bcrypt = new Bcrypt();
         $ckey = $data['nick'] . '_' . $data['password'] . '_' . $data['email'] . '_' . $data['name'] . '_' . $data['surname'];
         $this->confirmation_key = $bcrypt->create($ckey);
     } else {
         $this->confirmation_key = null;
     }
 }
Example #27
0
 /**
  * Preveri geslo uporabnika (vnos hasha in primerja z vnosom v bazi)
  *
  * @param string $user
  * @param string $passwordGiven
  */
 public static function checkPassword($user, $passwordGiven)
 {
     $bcrypt = new Bcrypt();
     $bcrypt->setSalt(5.129217031120145E+28);
     $bcrypt->setCost(5);
     $passwordGiven = $bcrypt->create($passwordGiven);
     if ($user->getEnabled()) {
         return $user->password === $passwordGiven ? true : false;
     } else {
         return false;
     }
 }
Example #28
0
 public function setPassword($user_id, $newPassword)
 {
     //Initialize variables
     $adapter = $this->sm->get('Zend\\Db\\Adapter\\Adapter');
     $sql = new Sql($adapter);
     $bcrypt = new Bcrypt();
     //create query
     $update = $sql->update('users_table')->set(array('password' => $bcrypt->create($newPassword)))->where(array('user_id' => $user_id));
     //execute query
     $sqlString = $sql->getSqlStringForSqlObject($update);
     $adapter->query($sqlString, $adapter::QUERY_MODE_EXECUTE);
 }
Example #29
0
 protected function changePassword(UserInterface $user, $password)
 {
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->getModuleConfig()->get('password_cost', 14));
     $pass = $bcrypt->create($password);
     $user->setPassword($pass);
     $user->setPasswordToken(null);
     // trigger event to allow password reset hooks
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user));
     $this->em()->flush();
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('user' => $user));
     return true;
 }
 public function resetPassword($password, $user, array $data)
 {
     $newPass = $data['newCredential'];
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->zfcUserOptions->getPasswordCost());
     $pass = $bcrypt->create($newPass);
     $user->setPassword($pass);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user));
     $this->getUserMapper()->update($user);
     $this->remove($password);
     $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('user' => $user));
     return true;
 }