如何使用substr在php中解密md5密码?
我正在共享我的2个文件的代码。用于插入用户名和密码以及检索数据。我的情况有所不同。如果用户名: abc和密码:123456789 在登录屏幕上,用户只需输入其密码中的3位数字。但这将是其密码中的随机数字。如果现在,系统将要求我输入密码中的第1位、第3位和第9位数字。重新加载页面后,它将随机更改。它将显示第二、第五和第四等 我以前用我的代码完成了这个任务。但现在我想用md5加密方法插入密码 我被困在这里,如果我使用md5加密,然后如何检索密码 insert.php:如何使用substr在php中解密md5密码?,php,mysql,login,md5,Php,Mysql,Login,Md5,我正在共享我的2个文件的代码。用于插入用户名和密码以及检索数据。我的情况有所不同。如果用户名: abc和密码:123456789 在登录屏幕上,用户只需输入其密码中的3位数字。但这将是其密码中的随机数字。如果现在,系统将要求我输入密码中的第1位、第3位和第9位数字。重新加载页面后,它将随机更改。它将显示第二、第五和第四等 我以前用我的代码完成了这个任务。但现在我想用md5加密方法插入密码 我被困在这里,如果我使用md5加密,然后如何检索密码 insert.php: <!DOCTYPE ht
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="" method="post">
<label>username</label>
<input type="text" name="username">
<label>pin</label>
<input type="password" name="pin">
<label>password</label>
<input type="password" name="password">
<button name="submit">Submit</button>
</form>
</body>
</html>
<?php
include 'conn.php';
if (isset($_POST['submit']))
{
$name = $_POST['username'];
$pass = md5($_POST['password']);
$sql = mysqli_query($conn,'INSERT INTO `emp`(`name`, `pass`) VALUES ("'.$name.'","'.$pass.'")');
if ($sql>0)
{
header('Location: index.php');
}
}
?>
用户名
大头针
暗语
提交
正如在评论中已经指出的,md5是一个单向散列函数,而不是加密函数。这意味着无法对哈希执行部分密码验证,因为无法检索原始密码
Smart Architects的博客上曾经有一篇关于部分密码验证的文章,但现在只能通过
总结各种可能性(省略完全不安全的明文存储密码解决方案):
以加密格式存储密码,这意味着您可以在需要进行比较时以纯文本形式检索密码。优点:易于实现。缺点:如果有人获得了密钥,那么所有密码都可以被撤销。如果你想要真正安全的东西,那么你可能需要一个HSM(硬件安全模块)来实现。在您接触到HSM之前,您可以尝试该功能
以哈希格式对接口可能要求的所有字母组合进行哈希。赞成:可能是最安全的存储格式(如果使用正确的哈希算法)。缺点:只要想想你需要为一个长密码创建多少条记录
使用Shamir秘密共享方案。赞成:在存储空间与安全性之间达成妥协。缺点:从编码的角度来看,可能是最难实现的解决方案
MD5()函数不是加密-解密函数。它根据输入生成数据。该数据无法还原。如果需要用普通文本检查MD5输出,则必须先检查MD5普通文本,然后比较两个MD5输出
存在多个联机MD5解密程序。它基于过去的输入历史。
你可以用这个检查一下
谢谢……请不要因为这些不是解密程序;他们只是根据数据库中的一组已知值查找哈希。。。。哈希本身无法解密,不管这些网站的名称如何
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
include 'conn.php';
if (isset($_POST['submit'])) {
$name = $_POST['username'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$pass3 = $_POST['pass3'];
$char1 = $_POST['char1'];
$char2 = $_POST['char2'];
$char3 = $_POST['char3'];
$sql = 'SELECT name,pass,pin from `emp` '
. 'where `name` = "'.$name.'" '
. 'AND SUBSTR(pass, '.($char1).', 1) = \''.$pass1.'\' '
. 'AND SUBSTR(pass, '.($char2).', 1) = \''.$pass2.'\' '
. 'AND SUBSTR(pass, '.($char3).', 1) = \''.$pass3.'\' ';
$sql = mysqli_query($conn,$sql);
$data = mysqli_fetch_assoc($sql);
if ($data)
{
echo 'success';
}
else
{
echo 'Fail';
}
}
// generate unique, not equal numbers
$char_pos = range(1, 9);
shuffle($char_pos);
$char_pos = array_slice($char_pos, 0, 3);
sort($char_pos);
?>
<form action="" method="post">
<input type="hidden" name="char1" value="<?php echo $char_pos[0]; ?>">
<input type="hidden" name="char2" value="<?php echo $char_pos[1]; ?>">
<input type="hidden" name="char3" value="<?php echo $char_pos[2]; ?>">
Username:
<input type="text" name="username" value="">
Password:
<input type="password" class="inputs" maxlength="1" name="pass1" placeholder='<?php echo $char_pos[0]; ?>st' value="">
<input type="password" class="inputs" maxlength="1" name="pass2" placeholder='<?php echo $char_pos[1]; ?>th' value="">
<input type="password" class="inputs" maxlength="1" name="pass3" placeholder='<?php echo $char_pos[2]; ?>th' value="">
<button name="submit">Submit</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(".inputs").keyup(function () {
if (this.value.length == this.maxLength) {
$(this).next('.inputs').focus();
}
});
</script>
</body>
</html>