每当给出正确的用户名时,将显示密码,但问题是if 密码是解密格式然后当我显示密码时,加密密码显示...表示密码是“通过”,其加密格式是“1a1dc91c907325c69271ddf0c944bc72”,然后第二次将其加密格式粘贴到密码框中。然后密码出错。我可以解决它吗?意味着如何解密javascript中的密码..
// Index.php页面从这里开始
<form name="login" method="post" action="upload_file_enter.php">
Username: <input type="text" id="name"name="username" onBlur="check()"><br>
<?php if(!$_COOKIE['password']){?>
Password: <input type="password" name="password"><br>
<?php };?>
<?php if(isset($_COOKIE['password'])){?>
Password: <input type="password" id="pass" name="password" value=""><br>
<?php };?>
Remember Me: <input type="checkbox" name="rememberme" value="1"><br>
<input type="submit" name="submit" value="Login!">
</form>
<script type="text/javascript">
//此函数检查用户名是否正确
function check()
{
var username=getCookie("username"); alert(username);
var name=document.getElementById("name").value;alert(name);
if(username==name)
{
document.getElementById("pass").value=getCookie("password"); //here pasting the
// enter code here`password in the password field if the username is correct
}
}
//从document.cookie获取cookie值
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
</script>
// Index.php页面在这里结束
// upload_file_enter.php //在这里设置cookie ..使用$ _POST并使用此处
从index.php中获取值<?php
/* These are our valid username and passwords */
$user = 'king1';
$pass = 'pass';
if(isset($_POST['username']) && isset($_POST['password'])) {
if (($_POST['username'] == $user) && ($_POST['password'] == $pass)) {
if (isset($_POST['rememberme'])) {//echo"asda";exit;
/* Set cookie to last 1 year */
setcookie('username', $_POST['username'], time()+60*60*24*365, '/');
setcookie('password', md5($_POST['password'])/*here encoded*/, time()+60*60*24*365, '/');
} else {
/* Cookie expires when browser closes */
setcookie('username', $_POST['username'], false, '/');
setcookie('password', md5($_POST['password'])/*here encoded*/, false, '/');
}
echo $p='showing some another page here';
} else {
echo 'Username/Password Invalid';
}
} else {
echo 'You must supply a username and password.';
}
?>
答案 0 :(得分:0)
如果你继续使用MD5 ......
MD5应该是un-decryptable
,因此通过JS检查的唯一方法是加密输入并根据cookie检查它,但是你需要找到一个针对JS的MD5剪辑。
试试这个http://phpjs.org/functions/md5/
我不会粘贴它的DAMN很长;)
e.g。
function md5(string){
//make string to md5
}
function check(){
var username=getCookie("username"); alert(username);
var name=document.getElementById("name").value; alert(name);
if(username==md5(name))
{
document.getElementById("pass").value=getCookie("password");
}
}
然而我建议使用更安全的算法来存储具有密钥/盐的密码。