assertEquals( $hash, auth_cryptPassword('foo' . $method, $method, 'abcdefgh12345678912345678912345678') ); } /** * @dataProvider hashes * @param $method * @param $hash */ function test_verifyPassword($method, $hash) { $this->assertTrue(auth_verifyPassword('foo' . $method, $hash)); $this->assertFalse(auth_verifyPassword('bar' . $method, $hash)); } /** * @dataProvider hashes * @param $method * @param $hash */ function test_verifySelf($method, $hash) { $hash = auth_cryptPassword('foo' . $method, $method); $this->assertTrue(auth_verifyPassword('foo' . $method, $hash)); } function test_bcrypt_self() { $hash = auth_cryptPassword('foobcrypt', 'bcrypt'); $this->assertTrue(auth_verifyPassword('foobcrypt', $hash)); } function test_verifyPassword_fixedbcrypt() { $this->assertTrue(auth_verifyPassword('foobcrypt', '$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC')); $this->assertTrue(auth_verifyPassword('lemmybcrypt12hash', '$2b$12$zMBuY6QAGXuT6elIbadavO1JTI6DfaGe1MpfBthG/nt6mkodwmKAi')); } function test_verifyPassword_nohash() { $this->assertTrue(auth_verifyPassword('foo', '$1$$n1rTiFE0nRifwV/43bVon/')); } function test_verifyPassword_fixedpmd5() { $this->assertTrue(auth_verifyPassword('test12345', '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); $this->assertTrue(auth_verifyPassword('test12345', '$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); } function test_verifypassword_drupal_sha512() { $this->assertTrue(auth_verifypassword('drupal_sha512', '$S$D7JxIm0f7QKO3zjwVS1RH4AW8sYvmLjO0.Rn4swH0JVt6OrZ4yzZ')); } function test_verifypassword_drupal_migrated_6to7() { $this->assertTrue(auth_verifypassword('pouette1234', 'U$S$9c47LGZuhR6TvhRQXzymkJIQ3mXthUCc6KDEGTt4B7eOL/H9Ykuy')); } function test_verifyPassword_seafilepbkdf2() { $hash='PBKDF2SHA256$10000$99227b6df52aa1394b5ca0aceee2733dd6c2670c85bbe26c751a2c65e79d4db7$d61dd1c4df6873c73813fe97f96d0e917792602a33966f3fab0eef154637cc84'; $pw='@STR0NGpassW0RD'; $this->assertTrue(auth_verifyPassword($pw, $hash)); } function test_veryPassword_mediawiki() { $this->assertTrue(auth_verifyPassword('password', ':B:838c83e1:e4ab7024509eef084cdabd03d8b2972c')); } /** * pmd5 checking should throw an exception when a hash with a too high * iteration count is passed */ function test_verifyPassword_pmd5Exception() { $except = false; try { auth_verifyPassword('foopmd5', '$H$abcdefgh1ZbJodHxmeXVAhEzTG7IAp.'); } catch(Exception $e) { $except = true; } $this->assertTrue($except); } function test_verifyPassword_sha256_crypt() { if(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) { $this->assertTrue(auth_verifyPassword('password', '$5$KvtIFskJlsLHR95A$CABu0dPozYsRq/dGNj4KITBQ21ZK.gC9KVXAkYFNE85')); $this->assertTrue(auth_verifyPassword('password', '$5$rounds=1000$FQM/YjSke3Iqsdma$RYwG1MP21u68qUBQKqHoz7GLpWlnA6tunNKMNH3nRh5')); } else { $this->markTestSkipped('SHA256 not available in this PHP environment'); } } /** * issue #2629, support PHP's crypt() format (with rounds=0 parameter) */ function test_verifyPassword_sha512_crypt() { if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) { $this->assertTrue(auth_verifyPassword('Qwerty123', '$6$rounds=3000$9in6UciYPFG6ydsJ$YBjypQ7XoRqvJoX1a2.spSysSVHcdreVXi1Xh5SyOxo2yNSxDjlUCun2YXrwk9.YP6vmRvCWrhp0fbPgSOT7..')); } else { $this->markTestSkipped('SHA512 not available in this PHP environment'); } } }