<commit_before><?php
/**
 * PasswordTest.php
 *
 * @category        AngryBytes
 * @package         Hash
 * @subpackage      Test
 * @copyright       Copyright (c) 2007-2016 Angry Bytes BV (http://www.angrybytes.com)
 */

namespace AngryBytes\Hash\Test;

use AngryBytes\Hash\Hash;
use AngryBytes\Hash\Hasher\Password as PasswordHasher;

/**
 * PasswordTest
 *
 * Testing password hasher
 *
 * @category        AngryBytes
 * @package         Hash
 * @subpackage      Test
 */
class PasswordTest extends TestCase
{
    /**
     * Test password hash creation
     */
    public function testHash()
    {
        $hasher = $this->createHasher();

        // Even though the password are equal the hashes should not be
        $this->assertNotEquals(
            $hasher->hash('foo'),
            $hasher->hash('foo')
        );
    }

    /**
     * Test password hash verification
     */
    public function testStringVerify()
    {
        $hasher = $this->createHasher();

        $this->assertTrue(
            $hasher->verify('foo', '$2y$15$l7l05fKprnFw8Lpgg2TZwuxqf2bKLolUxpJDruR6YiasGNkFZgfae')
        );

        $this->assertFalse(
            $hasher->verify('bar', '$2y$15$l7l05fKprnFw8Lpgg2TZwuxqf2bKLolUxpJDruR6YiasGNkFZgfae')
        );
    }

    /**
     * Test password hash rehash
     */
    public function testRehash()
    {
        $hasher = $this->createHasher();

        // Create hash
        $hash = $hasher->hash('foo');

        $this->assertFalse(
            $hasher->getHasher()->needsRehash($hash)
        );

        // Adjust the hash cost, this should require a rehash
        $hasher->getHasher()->setCost(16);

        $this->assertTrue(
            $hasher->getHasher()->needsRehash($hash)
        );
    }

    /**
     * Test invalid cost factor
     *
     * @expectedException \InvalidArgumentException
     */
    public function testCostTooLow()
    {
        $hasher = $this->createHasher();

        $hasher->getHasher()->setCost(2);
    }

    /**
     * Test invalid cost factor
     *
     * @expectedException \InvalidArgumentException
     */
    public function testCostTooHigh()
    {
        $hasher = $this->createHasher();<commit_msg>Update password unit test for new cost<commit_after><?php
/**
 * PasswordTest.php
 *
 * @category        AngryBytes
 * @package         Hash
 * @subpackage      Test
 * @copyright       Copyright (c) 2007-2016 Angry Bytes BV (http://www.angrybytes.com)
 */

namespace AngryBytes\Hash\Test;

use AngryBytes\Hash\Hash;
use AngryBytes\Hash\Hasher\Password as PasswordHasher;

/**
 * PasswordTest
 *
 * Testing password hasher
 *
 * @category        AngryBytes
 * @package         Hash
 * @subpackage      Test
 */
class PasswordTest extends TestCase
{
    /**
     * Test password hash creation
     */
    public function testHash()
    {
        $hasher = $this->createHasher();

        // Even though the password are equal the hashes should not be
        $this->assertNotEquals(
            $hasher->hash('foo'),
            $hasher->hash('foo')
        );
    }

    /**
     * Test password hash verification
     */
    public function testStringVerify()
    {
        $hasher = $this->createHasher();

        $this->assertTrue(
            $hasher->verify('foo', '$2y$10$Ch4CoMWaM6KR0ZfC3ZKvc.FAW1U30luCURlyahm/XgzJ4TWDwWPFW')
        );

        $this->assertFalse(
            $hasher->verify('bar', '$2y$10$Ch4CoMWaM6KR0ZfC3ZKvc.FAW1U30luCURlyahm/XgzJ4TWDwWPFW')
        );
    }

    /**
     * Test password hash rehash
     */
    public function testRehash()
    {
        $hasher = $this->createHasher();

        // Create hash
        $hash = $hasher->hash('foo');

        $this->assertFalse(
            $hasher->getHasher()->needsRehash($hash)
        );

        // Adjust the hash cost, this should require a rehash
        $hasher->getHasher()->setCost(15);

        $this->assertTrue(
            $hasher->getHasher()->needsRehash($hash)
        );
    }

    /**
     * Test invalid cost factor
     *
     * @expectedException \InvalidArgumentException
     */
    public function testCostTooLow()
    {
        $hasher = $this->createHasher();

        $hasher->getHasher()->setCost(2);
    }

    /**
     * Test invalid cost factor
     *
     * @expectedException \InvalidArgumentException
     */
    public function testCostTooHigh()
    {
        $hasher = $this->createHasher();
{'fraction_non_alphanumeric': 0.12906157691433764, 'fraction_numerical': 0.014542149511474665, 'mean_word_length': 2.0978184377199156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7381332', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1362, 'n_words': 257}