使用 php mysql 进行许可证检查

本文关键字:许可证 检查 php mysql 使用 | 更新日期: 2023-09-27 17:54:20

可能的重复项:
如何在PHP代码中安全地存储密码?

所以这是场景我有一个 C# 程序。它会将序列号发送到我的网站。(例如:www.example.com/LicenseCheck.php(假设它以串行形式发送 1234-1234-1234。

然后,许可证检查.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>";
?>

然后它将从有效的串行表中"选择",如果许可证存在于表中,则意味着它是有效的串行。

基本上,我试图找到解决这个问题的好方法。我最担心的是在哪里存储"用户名","密码"。基本上我只有一个用户只有读取权限。

我想尽可能地隐藏用户名和密码,并希望以安全的方式解决这个问题。

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

感谢您的所有帮助。

使用 php mysql 进行许可证检查

不再使用mysql函数。我将给你一个mysqli程序方法来解决你的解决方案。我还将包括一种保存密码的安全方法。

基本的 MySQL 连接和查询:

$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^');

所以基本上你的查询/获取将返回 true,如果COUNT(*)返回 1 如果用户名和密码等于 $username$passwordHASH .

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

看看这个答案的第二个要点。从本质上讲,您需要将MySQL连接详细信息放在文档根目录之外的配置文件中(例如public_html/等(,然后需要该文件。