admin管理员组

文章数量:1530085

以下是使用 PHP 编写的生成永远唯一的密钥码、激活码的自定义方法函数:

/**
 * 生成永远唯一的密钥码
 * sha512(返回128位) sha384(返回96位) sha256(返回64位) md5(返回32位)
 * 还有很多Hash函数......
 * @author xiaochaun
 * @param int $type 返回格式:0大小写混合  1全大写  2全小写
 * @param string $func 启用算法:                
 * @return string
 */
function create_secret($type=0, $func='sha512')
{
    $uid = md5(uniqid(rand(),true).microtime());
    $hash = hash($func, $uid);
    $arr = str_split($hash);
    foreach($arr as $v){
        if($type==0){
            $newArr[]= empty(rand(0,1)) ? strtoupper($v) : $v;
        }
        if($type==1){
            $newArr[]= strtoupper($v);
        }
        if($type==2){
            $newArr[]= $v;
        }
    }
    return implode('', $newArr);
}

本文标签: 密钥激活码案例教程PHP