2016-12-03 88 views
0

大家好,我为login创建了一个验证,其中login_id和密码是正确的,然后它会重定向到另一个页面,我的代码也在验证。但是我发现了一个错误,就是如果我在密码中输入密码,它也会采取正确的操作,而我的密码是在小信中,我不知道为什么它接受请给我解决方案谢谢。为什么我的密码接受小写和大写字母

<?php 
//include('connection.php'); 
if(isset($_POST['button'])) 
{ 
    session_start(); 
$con = mysqli_connect("localhost","root","","school"); 
echo $username=$_POST['username']; 
$password=$_POST['password']; 
//$sql="select * from login where username='$username' and password='$password'"; 
$sql = mysqli_query($con,"SELECT * from login where username='".$username."' AND password='".$password."' LIMIT 1"); 
//$query=mysqli_query($con,$sql); 
$count=mysqli_num_rows($sql); 
if($count > 0) 
{ 
echo $_SESSION['username']=$username; 
header("location:Dashboard.php"); 
} 
else 
{ 
//header("location:Login.php"); 
echo '<div class="alert alert-danger"> 
    <strong>username and password wrong!!!.</strong> 
    </div>'; 
} 
} 
?> 
+0

检查数据库中的密码,它是如何插入的?也许密码是以小写字母插入的。 – AnthonyB

+0

首先密码不直接保存安全原因。 –

+0

@AnthonyB我的密码是小写的 –

回答

0

我的猜测是你没有在MySQL中使用区分大小写的字符集。要么更改您的MySQL表格字符集,要么从数据库中选择密码并使用PHP进行比较。

+0

@Tomeage谢谢你....对了,我没有设置敏感的字符集 –

+0

无论如何,正如其他人所建议的,你应该使用Bcrypt来散列你的密码。将它作为明文存储是一个非常糟糕的主意:-) – Tomage

相关问题