/** * Encodes a raw string using Blowfish. * * @see KevinGH\Bcrypt\Bcrypt * * @param string $raw The raw string. * @param string $salt The salt. * @param integer $cost The cost. * @param boolean $broken Force broken implementation? * * @return string The encoded string. */ function bcrypt($raw, $salt = null, $cost = null, $broken = false) { $bcrypt = Bcrypt::create($broken); if (null !== $cost) { $bcrypt->setCost($cost); } if (null === $salt) { $bcrypt->setSalt($bcrypt->generateSalt()); } elseif (0 === strpos($salt, '$')) { $bcrypt->setEncoded($salt); } else { $bcrypt->setSalt($salt); } return $bcrypt($raw); }
/** * @depends testSetSalt */ public function testInvoke() { $bcrypt = new Bcrypt(); $bcrypt->setSalt('abcdefghijklmnopqrstuv'); $encoded = $bcrypt('test'); $bcrypt->setEncoded($encoded); $this->assertEquals($encoded, $bcrypt('test')); $this->assertRegExp('/^\\$2[axy]\\$\\d{1,2}\\$[a-zA-Z0-9\\.\\/]{22}[a-zA-Z0-9\\.\\/]+$/', $encoded); }