如何用 substr 解密 php 中的 md5 密码?
How to decrypt md5 passwords in php with substr?
我正在共享我的 2 个文件的 code.for 插入用户名和密码并检索数据。我的情况有所不同。如果用户名:
abc 和密码:123456789
在登录屏幕上,用户只需输入他的 password.But 中的 3 位数字,这将是他的密码中的随机数字。 如果现在系统会要求我输入第一位, password.after 重新加载页面的第 3 和第 9 位数字将随机更改。它将显示第 2、5 和 4 等等
我之前用我的代码完成了这个任务。但现在我想用md5加密方法插入密码。
如果我使用 md5 加密然后如何找回密码,我会卡在这里。
insert.php :
<!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');
}
}
?>
index.php:
<!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>
正如评论中已经指出的那样,md5 是一种单向散列函数,而不是加密。这意味着无法对哈希执行部分密码验证,因为无法检索原始密码。
Smart Architects 博客曾经有一篇关于部分密码验证的好文章,但现在只能通过 web archive 访问。
总结一下可能性(省略完全不安全的明文存储密码方案):
以加密格式存储密码,这意味着如果需要进行比较,您可以以明文形式检索密码。优点:易于实施。缺点:如果有人获得了密钥,那么所有的密码都可以被逆转。如果你想要真正安全的东西,那么你可能需要一个 HSM(硬件安全模块)。在您接触到 HSM 之前,您可以尝试 openssl_encrypt() 函数。
以哈希格式对界面可能要求的所有字母组合进行哈希处理。 Pro:可能是最安全的存储格式(如果正确的散列算法与盐一起使用)。缺点:想想你需要为长密码创建的记录数。
使用 Shamir 秘密共享方案。优点:存储 space 与安全性的妥协。缺点:从编码的角度来看,可能是最难实施的解决方案。
MD5() 函数不是加密解密函数。它根据输入生成数据。该数据无法还原。如果你需要检查普通文本的MD5输出,你必须MD5普通文本然后比较两个MD5输出。
目前有几个在线 MD5 解密器。它基于过去的输入历史。
www.md5online.org
你可以用这个检查..
谢谢...
我正在共享我的 2 个文件的 code.for 插入用户名和密码并检索数据。我的情况有所不同。如果用户名: abc 和密码:123456789
在登录屏幕上,用户只需输入他的 password.But 中的 3 位数字,这将是他的密码中的随机数字。 如果现在系统会要求我输入第一位, password.after 重新加载页面的第 3 和第 9 位数字将随机更改。它将显示第 2、5 和 4 等等
我之前用我的代码完成了这个任务。但现在我想用md5加密方法插入密码。
如果我使用 md5 加密然后如何找回密码,我会卡在这里。
insert.php :
<!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');
}
}
?>
index.php:
<!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>
正如评论中已经指出的那样,md5 是一种单向散列函数,而不是加密。这意味着无法对哈希执行部分密码验证,因为无法检索原始密码。
Smart Architects 博客曾经有一篇关于部分密码验证的好文章,但现在只能通过 web archive 访问。
总结一下可能性(省略完全不安全的明文存储密码方案):
以加密格式存储密码,这意味着如果需要进行比较,您可以以明文形式检索密码。优点:易于实施。缺点:如果有人获得了密钥,那么所有的密码都可以被逆转。如果你想要真正安全的东西,那么你可能需要一个 HSM(硬件安全模块)。在您接触到 HSM 之前,您可以尝试 openssl_encrypt() 函数。
以哈希格式对界面可能要求的所有字母组合进行哈希处理。 Pro:可能是最安全的存储格式(如果正确的散列算法与盐一起使用)。缺点:想想你需要为长密码创建的记录数。
使用 Shamir 秘密共享方案。优点:存储 space 与安全性的妥协。缺点:从编码的角度来看,可能是最难实施的解决方案。
MD5() 函数不是加密解密函数。它根据输入生成数据。该数据无法还原。如果你需要检查普通文本的MD5输出,你必须MD5普通文本然后比较两个MD5输出。
目前有几个在线 MD5 解密器。它基于过去的输入历史。 www.md5online.org
你可以用这个检查..
谢谢...