如何制作PHP串行代码系统

时间:2011-09-04 16:46:16

标签: php mysql license-key

我正在考虑使用有效的序列代码实现MySQL数据库,如果检查返回true,将根据用户输入检查并授予应用程序使用权限,但我知道这是因为用户(将使用一个基于localhost的应用程序)可以很容易地破解数据库并添加他自己的连续出版物(或者至少告诉其他对PHP和SQL有基本了解的人,如果他们认为应用程序来自“魔术盒”)。

由于我之前没有这样做过,有没有流行的做法?或者更好的是,如果你给我一些想法,那就太好了。

6 个答案:

答案 0 :(得分:1)

AFAIK如果他们拥有纯文本的PHP源代码,他们可以规避您实施的任何保护措施。

也就是说,有一些服务,例如ionCube(google it),它会混淆(编译?)代码,并需要一个密钥(来自某个远程服务器)来解锁代码以便执行。

或者您可以为客户托管软件,以便他们无法直接访问该应用程序。

答案 1 :(得分:1)

您可以实现“call home”,它会发送用户在其网站上输入的序列号。然后检查数据库中的序列号,并发送适当的回复,无论用户是否有权访问他的系统。您可以在用户登录其网站时执行此操作。

问题在于,由于在未使用Zend Guard等工具进行加密/编码时更改php文件非常容易,因此用户可以通过将调用更改为不进行操作来避免这种情况,并始终返回true。或者他们可以改变他们的web服务器的hosts文件,将请求重新路由到他们拥有的服务器,并在那里放置一个伪造你的支票的文件,并且总是返回true。

为防止这种情况发生,您必须加密php文件并实施质询 - 响应系统来检查其序列。

如果我明白你的意思。 :-P

答案 2 :(得分:0)

所以你的主机上有一个MySAL数据库,客户应用程序连接到它,对吗?

首先,我会在数据库和客户之间添加一层。一个http远程接口,如SOAP或使用json的东西。

您应该加密与它的连接(https)或至少使用一些质询响应方法。

但是当你的应用程序是开源的时候,总是可以绕过它。如果不是这样的话,那就是它; - )。

答案 3 :(得分:0)

永远不会有任何100%无法破解的方法。如果您有时间和专业知识, Anything 可以进行逆向工程。

但是你可以做些什么来最大化你不被破解的机会是使用某种预编译器/混淆器,如Zend GuardionCube(和others)来保护你的代码。大多数(全部?)都带有预先建立的许可功能,这绝对是推荐的方法。

这些问题是它们不是免费的......

修改

考虑到这一点,你可以在一组非常精确的环境中安全地实现这样的事情。如果你正在开发一些可以分发HipHop二进制文件的东西,你可以实现一些东西,而不必担心那些不太认真地知道自己在做什么的人会破解它。 HipHop是自由的available to download from github

远程数据库检查仍然是一个坏主意,因为人们可以嗅探网络流量并对密钥进行反向工程,或者学习如何欺骗响应(简单的hosts file编辑可以拦截网络流量)。您可以更好地对每个实例的密钥进行硬编码,并使用某种算法在每次调用时对其进行验证 - this siteGoogle可以帮助您。

答案 4 :(得分:-2)

看看http://dev.michaelnorris.co.uk/tests/random_string.php

<?php 
function makePin($lenth=10) { 
// makes a random alpha numeric string of a given lenth 
$aZ09 = array_merge(range('A', 'Z'), range('a', 'z'),range(0, 9));
//$aZ09 = array_merge(range('A', 'Z'), range(0, 9)); 
$out =''; 
for($c=0;$c < $lenth;$c++) { 
   $out .= $aZ09[mt_rand(0,count($aZ09)-1)]; 
} 
return $out; 
}
$obscure = makePin();
echo $obscure;
?>

答案 5 :(得分:-2)

我认为这对你来说实际上更好。看看http://dev.michaelnorris.co.uk/tests/random_password.php

我不能赞扬这个例子,因为我把它从网上的其他来源一起捣碎了,我记不住了,但无论如何它都在这里。

<?php

// just so we know it is broken
error_reporting(E_ALL);

//string passType can be alpha, numeric, or alphanumeric defaults to alphanumeric int $length is the length of the password, defaults to eight

class randomPassword{

    function __construct($passType='alphanumeric', $length=8, $rangeLength=9){
        $this->setLength($length);
        $this->setRangeLength($rangeLength);
        $this->passType = $this->setPassType($passType);
    }

    function setRangeLength($rangeLength){
        $this->rangeLength=$rangeLength;
    }

    // set the length of the password
    private function setLength($length){
        $this->length=$length;
    }


    // set the type of password
    private function setPassType($passType){
        return $passType.'Chars';
    }

    // return an array of numbers
    private function numericChars(){
        return range(0, $this->rangeLength);
    }

    // return an array of chars
    private function alphaChars(){
        return range('a', 'z');
    }

    // return an array of alphanumeric chars
    private function alphaNumericChars(){
        return array_merge($this->numericChars(), $this->alphaChars());
    }

    // return a string of chars
    private function makeString(){
        // here we set the function to call based on the password type
        $funcName = $this->passType;
        return implode($this->$funcName());
    }

    // shuffle the chars and return $length of chars
    public function makePassword(){
        return substr(str_shuffle($this->makeString()), 1, $this->length);
    }

} // end class

function randomPassword($length) {
    // create an array of chars to use as password
    $chars = implode(array_merge(range(0,9), range('a', 'z')));

    // randomly snarf $length number of array keys
    return substr(str_shuffle($chars), 1, $length);

}

/*
try
{
$obj = new randomPassword('alphanumeric', 16, 100);
echo $obj->makePassword().'<br />';
}
catch(Exception $ex)
{
echo $ex->getMessage();
}
*/
echo strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5)).'-'.strtoupper(randomPassword(5));
?>