<commit_before><?php defined('BASEPATH') OR exit('No direct script access allowed.');

/**
 * @author <NAME> <<EMAIL>>, 2014
 * @license The MIT License, http://opensource.org/licenses/MIT
 */

class Password {

    protected $key;

    public function __construct() {

        $this->key = (string) config_item('encryption_key_for_passwords');

        log_message('debug', 'Password class initialized');
    }

    // Added by <NAME>, 11-JUL-2014.
    // $min_length is not allowed to be less than 4.
    // If it not set, $max_length is assumed to be equal to $min_length.
    public function create($min_length = 10, $max_length = null) {

        $min_length = (int) $min_length;

        if ($min_length < 4) {
            $min_length = 4;
        }

        if ($max_length === null) {

            $max_length = $min_length;

        } else {

            $max_length = (int) $max_length;

            if ($max_length < $min_length) {
                $max_length = $min_length;
            }
        }

        $length = mt_rand($min_length, $max_length);

        return substr(base64_encode(random_pseudo_bytes($length)), 0, $length);
    }

    // See http://www.openwall.com/phpass/
    public function hash($password) {

        $password = (string) $password;

        // Don't allow empty passwords, on creation use validation for not accepting them.
        if ($password == '') {
            return '';
        }

        $hasher = new PasswordHash(8, false);

        return $hasher->HashPassword($password);
    }

    // See http://www.openwall.com/phpass/
    public function verify($password, $hash) {

        $password = (string) $password;
        $hash = (string) $hash;

        // Don't allow empty passwords, on creation use validation for not accepting them.
        if ($hash == '' || $password == '') {
            return false;
        }

        $hasher = new PasswordHash(8, false);

        return $hasher->CheckPassword($password, $hash) ? true : false;<commit_msg>Replacing a finction call.<commit_after><?php defined('BASEPATH') OR exit('No direct script access allowed.');

/**
 * @author <NAME> <<EMAIL>>, 2014
 * @license The MIT License, http://opensource.org/licenses/MIT
 */

class Password {

    protected $key;

    public function __construct() {

        $this->key = (string) config_item('encryption_key_for_passwords');

        log_message('debug', 'Password class initialized');
    }

    // Added by <NAME>, 11-JUL-2014.
    // $min_length is not allowed to be less than 4.
    // If it not set, $max_length is assumed to be equal to $min_length.
    public function create($min_length = 10, $max_length = null) {

        $min_length = (int) $min_length;

        if ($min_length < 4) {
            $min_length = 4;
        }

        if ($max_length === null) {

            $max_length = $min_length;

        } else {

            $max_length = (int) $max_length;

            if ($max_length < $min_length) {
                $max_length = $min_length;
            }
        }

        $length = mt_rand($min_length, $max_length);

        return substr(base64_encode(secure_random_bytes($length)), 0, $length);
    }

    // See http://www.openwall.com/phpass/
    public function hash($password) {

        $password = (string) $password;

        // Don't allow empty passwords, on creation use validation for not accepting them.
        if ($password == '') {
            return '';
        }

        $hasher = new PasswordHash(8, false);

        return $hasher->HashPassword($password);
    }

    // See http://www.openwall.com/phpass/
    public function verify($password, $hash) {

        $password = (string) $password;
        $hash = (string) $hash;

        // Don't allow empty passwords, on creation use validation for not accepting them.
        if ($hash == '' || $password == '') {
            return false;
        }

        $hasher = new PasswordHash(8, false);

        return $hasher->CheckPassword($password, $hash) ? true : false;
{'fraction_non_alphanumeric': 0.13567338810057256, 'fraction_numerical': 0.009957679860592481, 'mean_word_length': 2.206703910614525, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4109386', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1149, 'n_words': 318}