<commit_before><?php

/**
* Miva_Password
*
* Copyright (c) 2013, <NAME> <<EMAIL>>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of source code must retain the above copyright notice, this
*    list of conditions and the following disclaimer.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author <NAME> <<EMAIL>>
* @copyright 2013 <NAME> <<EMAIL>>
* @license http://opensource.org/licenses/BSD-2-Clause The BSD 2-Clause License
* @link http://www.github.com/Brandon0/Miva_Password
*/
class Miva_Password {
    /**
     * Miva's default length for a password salt
     * @var integer
     */
    static protected $salt_length = 8;

    /**
     * Create a unique salt string using the best source of random we can find
     *
     * @return string MIME base64
     */
    public static function create_salt() {
        $length = self::$salt_length;
        $salt = '';

        //mcrypt is our first choice
        if (function_exists('mcrypt_create_iv')) {
            $salt = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
            if (strlen($salt) >= $length) {
                return substr($salt, 0, $length);
            }
        }

        //else let's try /dev/urandom (doesn't work with Windows)
        if (is_readable('/dev/urandom') && ($fh = fopen('/dev/urandom', 'rb'))) {
            $salt = fread($fh, $length);
            fclose($fh);
            if (strlen($salt) >= $length) {
                return substr($salt, 0, $length);
            }
        }

        //worst case scenario we'll use a binary md5 hash pasted together
        $salt = '';
        for ($i=0; $i<$length; $i+=16) { //16 is the length of a raw md5 hash
            $salt .= md5(microtime(), true);
        }
        return substr($salt, 0, $length);
    }

    /**
     * Create a Miva Merchant compatible password hash. Follows the following format:
     *     PBKDF:hash-algorithim:iterations:salt-base64:ciphertext-base64
     *
     * @see http://extranet.mivamerchant.com/forums/showthread.php?110099-Miva-Merchant-5-Production-Release-8-Update-7-Customer-Password-Encryption-Info
     *
     * @param  string $password            The plain-text password to hash
     * @param  string $salt                The plain-text salt to use in the hash
     * @param  string $pbkdf_version       The PBKDF version to use; PBKDF1 by default
     * @param  string $hash_algo           The hashing algorithim to use; sha1 by default
     * @param  integer $iterations         The number of times to run the hashing algorithim; 1000 by default
     * @param  integer $derived_key_length The maximum string length enforced on the derived key; 20 by default
     * @return string                      A secure password hash string
     */
    public static function create_hash($password, $salt='', $pbkdf_version='PBKDF1', $hash_algo='sha1', $iterations=1000, $derived_key_length=20) {
        if ($salt === '') {
            $salt = self::create_salt();
        }
<commit_msg>fix for case insensitivity<commit_after><?php

/**
* Miva_Password
*
* Copyright (c) 2013, <NAME> <<EMAIL>>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of source code must retain the above copyright notice, this
*    list of conditions and the following disclaimer.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author <NAME> <<EMAIL>>
* @copyright 2013 <NAME> <<EMAIL>>
* @license http://opensource.org/licenses/BSD-2-Clause The BSD 2-Clause License
* @link http://www.github.com/Brandon0/Miva_Password
*/
class Miva_Password {
    /**
     * Miva's default length for a password salt
     * @var integer
     */
    static protected $salt_length = 8;

    /**
     * Create a unique salt string using the best source of random we can find
     *
     * @return string MIME base64
     */
    public static function create_salt() {
        $length = self::$salt_length;
        $salt = '';

        //mcrypt is our first choice
        if (function_exists('mcrypt_create_iv')) {
            $salt = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
            if (strlen($salt) >= $length) {
                return substr($salt, 0, $length);
            }
        }

        //else let's try /dev/urandom (doesn't work with Windows)
        if (is_readable('/dev/urandom') && ($fh = fopen('/dev/urandom', 'rb'))) {
            $salt = fread($fh, $length);
            fclose($fh);
            if (strlen($salt) >= $length) {
                return substr($salt, 0, $length);
            }
        }

        //worst case scenario we'll use a binary md5 hash pasted together
        $salt = '';
        for ($i=0; $i<$length; $i+=16) { //16 is the length of a raw md5 hash
            $salt .= md5(microtime(), true);
        }
        return substr($salt, 0, $length);
    }

    /**
     * Create a Miva Merchant compatible password hash. Follows the following format:
     *     PBKDF:hash-algorithim:iterations:salt-base64:ciphertext-base64
     *
     * @see http://extranet.mivamerchant.com/forums/showthread.php?110099-Miva-Merchant-5-Production-Release-8-Update-7-Customer-Password-Encryption-Info
     *
     * @param  string $password            The plain-text password to hash
     * @param  string $salt                The plain-text salt to use in the hash
     * @param  string $pbkdf_version       The PBKDF version to use; PBKDF1 by default
     * @param  string $hash_algo           The hashing algorithim to use; sha1 by default
     * @param  integer $iterations         The number of times to run the hashing algorithim; 1000 by default
     * @param  integer $derived_key_length The maximum string length enforced on the derived key; 20 by default
     * @return string                      A secure password hash string
     */
    public static function create_hash($password, $salt='', $pbkdf_version='PBKDF1', $hash_algo='sha1', $iterations=1000, $derived_key_length=20) {
        if ($salt === '') {
            $salt = self::create_salt();
        }
        $pbkdf_version = strtoupper($pbkdf_version);

{'fraction_non_alphanumeric': 0.09824475865431496, 'fraction_numerical': 0.013164310092637738, 'mean_word_length': 2.803894297635605, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '7422527', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2246, 'n_words': 857}