Php 登录脚本产生不匹配错误

Php 登录脚本产生不匹配错误,php,mysqli,Php,Mysqli,我正在开发一个注册和登录脚本,并根据Larry Ullan的quickpro指南(以及php手册和其他参考资料)对脚本进行建模。我的注册脚本运行良好,但在尝试登录脚本时遇到了问题。我向DB发出如下查询: $q = "SELECT user_id, first_name FROM registration WHERE email='$ue' AND pass=SHA1('$p')"; 我将收到错误消息: 输入的电子邮件地址和密码与文件中的不匹配 如果我像这样删除和pass=SHA1('

我正在开发一个注册和登录脚本,并根据Larry Ullan的quickpro指南(以及php手册和其他参考资料)对脚本进行建模。我的注册脚本运行良好,但在尝试登录脚本时遇到了问题。我向DB发出如下查询:

    $q = "SELECT user_id, first_name FROM registration WHERE email='$ue' AND  pass=SHA1('$p')";
我将收到错误消息:

输入的电子邮件地址和密码与文件中的不匹配

如果我像这样删除
和pass=SHA1('$p')

    $q = "SELECT user_id, first_name FROM registration WHERE email='$ue'";
脚本会引导我进入一个登录页面

我已经一遍又一遍地查看注册脚本和登录函数脚本,试图找到断开连接,但我就是看不到。以下是我的注册脚本摘录:

    //Check for a password and match against the confirmed password:

    if (!empty($_POST['pass1'])) {

    if ($_POST['pass1'] != $_POST['pass2']) {

    $errors[] = 'Your password did not match the confirmed password.';

    }else{

    $p = mysqli_real_escape_string($dbc, trim($_POST['pass1']));

    }

    }else{

    $errors[] = 'You forgot to enter your password.';

    }

    //////////////////////////////////////////////////// password parameters

   if( strlen($p) < 8 ) {

    $errors[]= "Password too short! ";
    }

    if( strlen($p) > 15 ) {

    $errors[]= "Password too long! ";

   }

    if( !preg_match("#[0-9]+#", $p)  {

    $errors[]= "Password must include at least one number! ";

    }


    if( !preg_match("#[a-z]+#", $p) ) {

    $errors[]= "Password must include at least one letter! ";

    }
   if( !preg_match("#[A-Z]+#", $p) ) {

    $errors[]= "Password must include at least one CAPS! ";
    }

    if( !preg_match("#\W+#", $p) ) {

    $errors[]= "Password must include at least one symbol! ";

    }   

    ////////////////////////////////////////////////////
    function check_login($dbc, $email ='', $pass='') {


    $errors = array(); // Initialize error array.


    //validate email

    if (empty($email)) {

    $errors[]='You forgot to enter your email address.';

    }else{

    $ue = mysqli_real_escape_string($dbc, trim($email));

    } 


    //validate password
    if (empty($pass)) {

    $errors[]='You forgot to enter your password.';

    }else{

    $p = mysqli_real_escape_string($dbc, trim($pass));

    } 


    if (empty($errors)) { // if passed validation

    //call to DB at beginning of login script

    //retrieve user id and first name for that email/password combo

    $q = "SELECT user_id, first_name FROM registration WHERE email='$ue' AND  pass=SHA1('$p')";

    $r = mysqli_query ($dbc, $q);


    //check results
    if (mysqli_num_rows($r) == 1) {


    //fetch the record

    $row = mysqli_fetch_array ($r, MYSQLI_ASSOC);


    return array(true, $row);

    }else{  // not a match

    $errors[]= 'The email address and password entered do not match those on  file';

    }

    }  // End of empty ($errors) IF


    //return false and the errors:

    return array(false, $errors);


    } //End of check_login() function

我已经尝试了我能想到的每一种调试技术,或者在搜索互联网时发现的每一种调试技术(并不意味着我没有错过任何东西)。我搜索了这个网站,没有找到我的问题的答案。我希望有人能给我一个答案,因为我真的不知道该怎么办。我已经一行一行地看了这两个脚本。我错过了什么?

我的天啊!我发现了我的问题,至少可以说答案很尴尬。我想与大家分享这一点,这样可以节省其他人数小时的调试时间。我没有为我为什么这么做提供任何借口,但我已经将“pass”的列宽设置为20,而不是SHA1所需的40个字符。我真的不喜欢落在自己的剑上,但希望它能让别人免于痛苦

你是否碰巧将密码存储在纯文本中?你是否尝试过在密码字段中回显数据库中的内容,并显示sha1($password)返回的内容?现在所有酷孩子都在做的一件新事情就是缩进你的代码。你应该试试ti。谢谢developerJK的反馈,下次我会尽量记住的。