登录脚本产生不匹配错误


Login script produces mismatch error

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

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

我将收到错误消息:

The email address and password entered do not match those on file

如果我像这样删除AND 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,而不是 SHA40 所需的 1 个字符。 我真的不喜欢摔在自己的剑上,但希望它能省去别人的痛苦。