1

こんにちは、ログインページで作業しています。ユーザー名を入力してログインすると、ページが間違ったユーザー名またはパスワードをエコーするように変更されるという問題があります。

login_success.php にアクセスしていないようです。これは、問題が SQL 構文にあると考えさせますが、その理由についてはまだ答えを見つけていません。私はまた、それが if($count==1){ である可能性があると考え、 ($count>1){ を試しましたが成功しませんでした。

私はネットを検索し、いくつかの異なるアプローチを試みましたが、何も機能しませんでした。私は新しいので、sqlinjection を停止する方法を検討しますが、このサイトはライブではなく、練習用です :) このコミュニティは私の学習に大きな助けとなりました。

HTML LoginPage.html

<form id=login name="login" action="login.php" method="post">
   <fieldset id=fs>
      <legend>Vault Security Console:</legend>
      <!-- legeng tage creates a header title for the fieldset box, filedset pulls all data in the tag to gether with a box around it. -->
      UserName: <input type="text" name="username"> <br>
      Password: <input type="password" name="password"> <br>
      <input type="submit" value="Login"> <input type="submit" value="Register"> 
   </fieldset>
</form>

php-Login.php

<?php
   // Create connection
   $con=mysqli_connect('172.16.254.111',"user","password","Faults"); //(connection location , username to sql, password to sql, name of db)

   // Check connection
   if (mysqli_connect_errno($con))
   {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   //below is the variables from the login form
   $username = $_POST['username'];

   $password = md5(strip_tags($_POST['password']));

   $sql="SELECT * FROM Users WHERE username='.addslashes($username).' and password='.addslashes($password).'";
   $result=mysqli_query($sql);   

   //Mysql_num_row is counting table row
   $count=mysqli_num_rows($result);   

   if($count==1){   
   session_register("username");
     session_register("password"); 
   header('location:login_success.php');
   }
   //if false echo below
   else {
    echo "<H2>Wrong Username or Password</H2>";
   }   
?>
4

3 に答える 3

0

ユーザー名かパスワードのどちらかに問題があると思います。
次の手順に従う必要があります:-

  1. ログインユーザーに対応するパスワードを選択
  2. スクリプトが生成しているエンコードされたパスワードと比較してください
 $username = mysqli_real_escape_string($con, $_POST['username']);
 $recievedPassword = md5($_POST['password']);

$qry="select password from Users where username=$username";
$row=mysqli_query($qry);

$result=mysqli_fetch_assoc($result);
$dbPassword=$result['passsword'];

if($recievedPassword==$dbPassword){
    echo "password matched"; 
}
else{
    echo "password mismatch, Please not encryped in db or there is any space..";
}
于 2013-07-04T15:24:33.360 に答える