使用Php Mysql进行许可证检查

时间:2013-01-19 09:31:20

标签: c# php mysql apache licensing

  

可能重复:
  How to safely store a password inside PHP code?

所以这就是场景 我有一个C#程序。 它会将序列号发送到我的网站。 (例如:www.example.com/LicenseCheck.php) 让我们说它发送1234-1234-1234作为序列。

然后licenseCheck.php将连接到我的mysql:

<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>

然后它将从有效的串行表中进行“选择”,如果表中存在许可证,则表示它是有效的序列号。

基本上,我试图找到什么是一个很好的方法来解决这个问题。 我最担心的是存储“用户名”,“密码”的位置。基本上我只有一个用户只有读取权限。

我想尽可能隐藏用户名和密码,并希望以安全的方式处理此问题。

“安全”是什么意思?只是一种方法可以防止未经授权的用户进入我的数据库。

感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

不再使用mysql函数。我将为您的解决方案提供一个mysqli程序方法。我还将提供一种保存密码的安全方法。

基本的mysqli连接和查询:

$queryString = "SELECT COUNT(*) FROM table WHERE userName = ? AND password=?";//not the question marks
//the question marks are used to bind our parameters/variables so the query string cannot be adjusted I believe? 
$DBH=mysqli_connect('local','user','pass');
mysqli_select_db($DBH,'database');
$query = mysqli_prepare($DBH,$queryString);
mysqli_bind_param($query,'ss',$username,$passwordHASH);//the second parameter declares the datatypes 
mysqli_execute($query);
//mysqli_bind_result($results); ||not needed in this situation but this is how you'd get results from the database
if(mysqli_fetch($query)){ //adding  && $results = 1 would insure there is only one record
    //username and password match
}
else{
    //error builder etc
}

现在,为了您的密码,我建议使用hmac_hash()来提供保护。将密码插入数据库时​​,确保在查询数据库时它们hmac_hash(),这些都受到保护。

$passwordHASH = hash_hmac('sha512',$hashThis, '&R4nD0m^');

因此,如果COUNT(*)如果用户名和密码等于$username$passwordHASH则返回1,则基本上您的查询/获取将返回true。

但是已经说过所有你不能在C#中使用#include <mysql.h> mysql库?

答案 1 :(得分:0)

看一下this answer的第二个要点。基本上,您需要将MySQL连接详细信息放在文档根目录之外的配置文件中(例如public_html /等),然后需要该文件。

相关问题