2016-12-03 87 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

相關問題