MySQLI到PDO密码验证。难倒

时间:2016-02-23 18:04:46

标签: mysqli pdo

我使用mysqli完成了密码验证功能。我试图使用PDO转换它(是的,我在发布之前已经找到了解决方案),但我找不到一个模拟我现有代码的解决方案。简而言之,我很难进行转换。以下是我的原始代码。

if(isset($_POST["user_name"])&& isset($_POST["pass1"])){

//assign variables
$manager = $_POST["user_name"];
$password = $_POST["pass1"];

//connect to db
include ("db_connect.php");

//run query 
$sql = "SELECT id, pass1 FROM admin WHERE user_name='$manager' LIMIT 1";
  $result = mysqli_query($conn, $sql);
  $row = mysqli_fetch_assoc($result);
  $hash = $row["pass1"];


//run password against hash
if(password_verify($password, $hash)){
    while($row = mysqli_fetch_array($sql)){

         $id = $row['id'];   
     }

     $_SESSION["id"]=$id;
     $_SESSION["manager"]=$manager;
     $_SESSION["password"]=$password;
     header('Location: adminDashboard.php');

    exit();
}else{
  $failLoginMsg = '<p>That information was incorrect, try again <a href="admin_login.php">Click here</a></p>';

}

}

特别是,如何将$ row和$ hash变量合并到PDO :: FETCH_ASSOC中已经失去了我。

感谢您的意见。

0 个答案:

没有答案