/**
  * @param Schema $schema
  */
 public function up(Schema $schema)
 {
     // this up() migration is auto-generated, please modify it to your needs
     $enc = new BCryptPasswordEncoder(10);
     $p = $enc->encodePassword('Au123456', null);
     $this->addSql("INSERT INTO user\n        (`username`, `password`, `first_name`, `last_name`, `role`, `email`, `email_is_verify`) VALUES\n        ('testuser', '{$p}', 'DemoUser', 'DemoUser', 0, '*****@*****.**', 1)");
 }
 /**
  * @requires PHP 5.3.7
  */
 public function testCheckPasswordLength()
 {
     $encoder = new BCryptPasswordEncoder(self::VALID_COST);
     $result = $encoder->encodePassword(str_repeat('a', 72), null);
     $this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt'));
     $this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt'));
 }
 public function testValidation()
 {
     $this->skipIfPhpVersionIsNotSupported();
     $encoder = new BCryptPasswordEncoder(self::VALID_COST);
     $result = $encoder->encodePassword(self::PASSWORD, null);
     $this->assertTrue($encoder->isPasswordValid($result, self::PASSWORD, null));
     $this->assertFalse($encoder->isPasswordValid($result, 'anotherPassword', null));
 }
Exemple #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $encoder = new BCryptPasswordEncoder(10);
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setPassword($encoder->encodePassword('nhy6&UJM', null));
     $user->setEnabled(1);
     $user->setRoles('ROLE_USER');
     $user->setCreated(new \Datetime());
     $manager->persist($user);
     $manager->flush();
     $currencyDollar = new Currency();
     $currencyDollar->setName('United States dollar');
     $currencyDollar->setCode('USD');
     $currencyDollar->setSymbol('$');
     $manager->persist($currencyDollar);
     $manager->flush();
     $currencyEuro = new Currency();
     $currencyEuro->setName('Euro');
     $currencyEuro->setCode('EUR');
     $currencyEuro->setSymbol('€');
     $manager->persist($currencyEuro);
     $manager->flush();
     $currencySol = new Currency();
     $currencySol->setName('Peruvian Nuevo Sol');
     $currencySol->setCode('PEN');
     $currencySol->setSymbol('S/.');
     $manager->persist($currencySol);
     $manager->flush();
     $account1 = new Account();
     $account1->setOwner($user);
     $account1->setName('Checking');
     $account1->setCurrency($currencyDollar);
     $account1->addTransaction(10000, 'Initial Deposit', new \DateTime());
     $account1->addTransaction(2500, 'July Paycheck', new \DateTime());
     $manager->persist($account1);
     $manager->flush();
     $accId = $account1->getId();
     $acc1 = $manager->find('Pfmgr\\Entity\\Account', $accId);
     $acc2 = $manager->find('Pfmgr\\Entity\\Account', $accId);
     $acc1->addTransaction(-1650, 'Rent', new \DateTime());
     $acc2->addTransaction(-845.45, 'Audi A8 Payment', new \DateTime());
     $manager->persist($acc1);
     $manager->persist($acc2);
     $manager->flush();
     $account2 = new Account();
     $account2->setOwner($user);
     $account2->setName('Checking');
     $account2->setCurrency($currencyEuro);
     $manager->persist($account2);
     $manager->flush();
 }
 public function testSecureRandomIsUsed()
 {
     if (function_exists('mcrypt_create_iv')) {
         return;
     }
     $this->secureRandom->expects($this->atLeastOnce())->method('nextBytes');
     $encoder = new BCryptPasswordEncoder($this->secureRandom, self::VALID_COST);
     $result = $encoder->encodePassword(self::PASSWORD, null);
     $prefix = '$' . (version_compare(phpversion(), '5.3.7', '>=') ? '2y' : '2a') . '$';
     $salt = 'MDEyMzQ1Njc4OWFiY2RlZe';
     $expected = crypt(self::PASSWORD, $prefix . self::VALID_COST . '$' . $salt);
     $this->assertEquals($expected, $result);
 }
 /**
  * @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
  */
 public function testEncodePasswordLength()
 {
     $encoder = new BCryptPasswordEncoder(self::VALID_COST);
     $encoder->encodePassword(str_repeat('a', 5000), 'salt');
 }
Exemple #7
0
 /**
  * @param string $currentPassword
  *
  * @return string
  */
 protected function getEncodedPassword($currentPassword)
 {
     $newPassword = $currentPassword;
     if (mb_substr($currentPassword, 0, 2) !== '$2') {
         $encoder = new BCryptPasswordEncoder(self::BCRYPT_FACTOR);
         $newPassword = $encoder->encodePassword($currentPassword, self::BCRYPT_SALT);
     }
     return $newPassword;
 }
 /**
  * Set old password
  *
  * @param string $oldPassword
  *
  * @return TestUser
  */
 public function setOldPassword($password)
 {
     $encoder = new BCryptPasswordEncoder(static::bcryptStrength);
     $this->oldPassword = $encoder->encodePassword($password, $this->getSalt());
     return $this;
 }
 public function changePassword($newPassword)
 {
     $bcrypt = new BCryptPasswordEncoder(BCRYPT_COST);
     $this->password = $bcrypt->encodePassword($newPassword, null);
     $this->remember_code = null;
 }
 public function setPassword($newPassword)
 {
     $bcrypt = new BCryptPasswordEncoder(BCRYPT_COST);
     $this->password = $bcrypt->encodePassword($newPassword, null);
 }
 /**
  * @param string $plainPassword
  * @param string $salt
  *
  * @return string
  */
 public static function encode($plainPassword, $salt)
 {
     $encoder = new BCryptPasswordEncoder(13);
     return $encoder->encodePassword($plainPassword, $salt);
 }