<commit_before><?php

declare(strict_types=1);

namespace Concrete\Tests\Encryption;

use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Encryption\PasswordHasher;
use Concrete\Core\Legacy\PasswordHash;
use Concrete\Tests\TestCase;

class PasswordHasherTest extends TestCase
{

    private function hasher(
        string $algorithm = PASSWORD_BCRYPT,
        ?int $cost = null,
        array $hashOptions = [],
        bool $portable = false
    ) {
        $config = \Mockery::mock(Repository::class);

        $config->shouldReceive('get')->with('concrete.user.password.hash_algorithm')->andReturn($algorithm);
        $config->shouldReceive('get')->with('concrete.user.password.hash_options', [])->andReturn($hashOptions);
        $config->shouldReceive('get')->with(
            'concrete.user.password.hash_cost_log2',
            PASSWORD_BCRYPT_DEFAULT_COST
        )->andReturn($cost);
        $config->shouldReceive('get')->with('concrete.user.password.hash_portable')->andReturn($portable);

        return new PasswordHasher($config);
    }

    /**
     * @dataProvider portableHashes
     */
    public function testPortableHashesSucceed(string $password, string $hash)<commit_msg>Remove type hint for algorithm so that older int constants pass through properly.<commit_after><?php

declare(strict_types=1);

namespace Concrete\Tests\Encryption;

use Concrete\Core\Config\Repository\Repository;
use Concrete\Core\Encryption\PasswordHasher;
use Concrete\Core\Legacy\PasswordHash;
use Concrete\Tests\TestCase;

class PasswordHasherTest extends TestCase
{

    private function hasher(
        $algorithm = PASSWORD_BCRYPT,
        ?int $cost = null,
        array $hashOptions = [],
        bool $portable = false
    ) {
        $config = \Mockery::mock(Repository::class);

        $config->shouldReceive('get')->with('concrete.user.password.hash_algorithm')->andReturn($algorithm);
        $config->shouldReceive('get')->with('concrete.user.password.hash_options', [])->andReturn($hashOptions);
        $config->shouldReceive('get')->with(
            'concrete.user.password.hash_cost_log2',
            PASSWORD_BCRYPT_DEFAULT_COST
        )->andReturn($cost);
        $config->shouldReceive('get')->with('concrete.user.password.hash_portable')->andReturn($portable);

        return new PasswordHasher($config);
    }

    /**
     * @dataProvider portableHashes
     */
    public function testPortableHashesSucceed(string $password, string $hash)
{'fraction_non_alphanumeric': 0.13341394598952036, 'fraction_numerical': 0.0016122531237404273, 'mean_word_length': 3.763915547024952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4759914', 'n_tokens_mistral': 734, 'n_tokens_neox': 700, 'n_words': 112}