<commit_before><?php
/**
 * Mapster
 *
 * @copyright Ninelabs 2013
 * @author <NAME> <<EMAIL>>
 * @since v0.1.0
 */

namespace Blueridge\Utilities;

/**
 * Doorman
 * 
 * Doorman helps you generate and validate keys and access codes
 * @package Blueridge
 */
class Doorman
{
    /**
     * get a generated code
     * @param  String $code Can be null
     * @return Array
     */
    public static function getCode($code = null)
    {
        if(empty($code)){
            $code = self::generateCode();    
        }

        $key = password_hash($code, PASSWORD_BCRYPT);
        return ['key'=>$key,'code'=>$code];
    }
    
    /**
     * Validate code against key
     * 
     * @param String $code
     * @param String $key
     */
    public static function validate($code,$key)
    {
        return password_verify($code, $key);
    }

    /**
     * Generate a 16 digit random code
     * @return String code
     */
    public static function generateCode()
    {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#-_&%$*(){}[]=+;:";           
        $password = substr(str_shuffle( $chars ), 0, 16 );
        return $password;
    }
}<commit_msg>no moar crude random generator<commit_after><?php
/**
 * Mapster
 *
 * @copyright Ninelabs 2013
 * @author <NAME> <<EMAIL>>
 * @since v0.1.0
 */

namespace Blueridge\Utilities;

/**
 * Doorman
 * 
 * Doorman helps you generate and validate keys and access codes
 * @package Blueridge
 */
class Doorman
{
    /**
     * get a generated code
     * @param  String $code Can be null
     * @return Array
     */
    public static function getCode($code = null)
    {
        if(empty($code)){
            $code = bin2hex(openssl_random_pseudo_bytes(8));  
        }

        $key = password_hash($code, PASSWORD_BCRYPT);
        return ['key'=>$key,'code'=>$code];
    }
    
    /**
     * Validate code against key
     * 
     * @param String $code
     * @param String $key
     */
    public static function validate($code,$key)
    {
        return password_verify($code, $key);
    }
}
{'fraction_non_alphanumeric': 0.13612313612313612, 'fraction_numerical': 0.014911014911014911, 'mean_word_length': 2.2449297971918876, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '3939193', 'n_tokens_mistral': 696, 'n_tokens_neox': 658, 'n_words': 164}