doushuo1989 2013-03-31 23:56
浏览 35
已采纳

忘记密码页面,电子邮件/用户名表单和新密码表单

Basically if the user comes to the page they get a form where they type in their username. That then checks against the db and then adds a generated key to their row in the db and emails the key link to them. The link brings them back to the same page but with a different form asking to update their password.

This is where my problem lies. The script first checks if that key exists. Even though it does exist I keep getting the uh oh key does not exist error. I've read through it a few times, taken breaks and still can't get it. Hopefully someone here can catch the issue!

Snippet of the problem:

<?php
  if ($_GET['do'] == "password") {
    $forgetKeyEmail = mysql_real_escape_string($_GET['key']);

    if ($forgetKeyEmail !== "") {
      $keyQuery = mysql_query("SELECT * FROM users WHERE forgetKey = '$forgetKeyEmail' LIMIT 1");
      $keyCheck - mysql_num_rows($keyQuery);

      if ($keyCheck == 1) {
      ?>

        form goes here to update password

      <?php
        if ($_GET['do'] == "update") {
          $hasher = new PasswordHash(10, false);
          $resetPasswdord = $hasher->HashPassword(mysql_real_escape_string($_POST['inputPassword']));
          $resetPassword = $_POST['inputPassword'];

          if ($_POST['inputPassword'] !== "") {
            mysql_query("UPDATE users SET password = '$resetPassword' WHERE forgetKey = '$forgetKeyEmail'");
            echo "g";
          ?>
success message
          <?php
          }
          else {
          ?>
          empty field message
          <?php
          }
        }
      }
      else{
      ?>
incorrect key message (what I keep getting)
      <?php
      }
    }
  }

Full code:

<?php
      if ($_GET['do'] == "password") {
        $forgetKeyEmail = mysql_real_escape_string($_GET['key']);

        if ($forgetKeyEmail !== "") {
          $keyQuery = mysql_query("SELECT * FROM users WHERE forgetKey = '$forgetKeyEmail' LIMIT 1");
          $keyCheck - mysql_num_rows($keyQuery);

          if ($keyCheck == 1) {
          ?>

            <form method="POST"class="form-horizontal" action="?do=update&key=<?php echo $forgetKeyEmail; ?>" >
              <div class="control-group">
                <label class="control-label" for="inputPassword">New Password</label>
                <div class="controls">
                  <input type="text" id="inputPassword" name="inputPassword" placeholder="Password">
                </div>
              </div>
              <div class="control-group">
                <div class="controls">
                  <button type="submit" class="btn btn-primary">Reset!</button>
                </div>
              </div>
            </form>

          <?php
            if ($_GET['do'] == "update") {
              $hasher = new PasswordHash(10, false);
              $resetPasswdord = $hasher->HashPassword(mysql_real_escape_string($_POST['inputPassword']));
              $resetPassword = $_POST['inputPassword'];

              if ($_POST['inputPassword'] !== "") {
                mysql_query("UPDATE users SET password = '$resetPassword' WHERE forgetKey = '$forgetKeyEmail'");
                echo "g";
              ?>
              <div class="alert alert-success" style="margin:0;">
                <strong>Woooo!</strong> Your password has been changed, you can now <a href="login.php">login.</a>
              </div>
              <?php
              }
              else {
              ?>
              <div class="alert alert-error" style="margin:0;">
                <strong>Woops!</strong> You need to fill out a password!
              </div>
              <?php
              }
            }
          }
          else{
          ?>
          <div class="alert alert-error" style="margin:0;">
            <strong>Uh oh!</strong> That key is incorrect.
          </div>
          <?php
          }
        }
      }

      elseif ($_GET['do'] == "reset") {
        $resetUsername = mysql_real_escape_string($_POST['inputUser']);
        if ($resetUsername !== "") {
          $checkQuery = mysql_query("SELECT * FROM users WHERE username = '$resetUsername' LIMIT 1");
          $checkExist = mysql_num_rows($checkQuery);
          $userData = mysql_fetch_array($checkQuery);
          $mailEmail = $userData['email'];

          if ($checkExist == 1) {
            $forgetKey = genRandomString() . genRandomString();
            mysql_query("UPDATE users SET forgetKey = '$forgetKey' WHERE username = '$resetUsername'");

            $message = "Hey there, ".$resetUsername." - We've received a request to reset your password. <br /><br /> Please click the following link to do so: <a href=\"http://localhost/vanilla/forgot.php?do=reset&key=".$forgetKey."\"";

            echo $forgetKey;
            mail($mailEmail, 'realvanil.la Password Reset', $message);
          ?>

            <div class="alert alert-info" style="margin:0;">
              An email has been sent to <strong><?php echo $userData['email']; ?></strong> with your reset information!
            </div>

          <?php
          }
          else {
          ?>

            <div class="alert alert-error">
              <strong>Uh oh!</strong> We can't seem to find an account with that username. Remember, it's your Minecraft username!
            </div>

            <form method="POST"class="form-horizontal" action="?do=reset" >
              <div class="control-group">
                <label class="control-label" for="inputUser">Username</label>
                <div class="controls">
                  <input type="text" id="inputUser" name="inputUser" placeholder="Username">
                </div>
              </div>
              <div class="control-group">
                <div class="controls">
                  <button type="submit" class="btn btn-primary">Send Email!</button>
                </div>
              </div>
            </form>

        <?php
        }
      }
      else {
      ?>

      <div class="alert alert-error">
        <strong>Uh oh!</strong> You need to tell us your username ;)
      </div>

      <form method="POST"class="form-horizontal" action="?do=reset" >
        <div class="control-group">
          <label class="control-label" for="inputUser">Username</label>
          <div class="controls">
            <input type="text" id="inputUser" name="inputUser" placeholder="Username">
          </div>
        </div>
        <div class="control-group">
          <div class="controls">
            <button type="submit" class="btn btn-primary">Send Email!</button>
          </div>
        </div>
      </form>   

      <?php
        }
    }
    else {
    ?>

  <form method="POST"class="form-horizontal" action="?do=reset" >
    <div class="control-group">
      <label class="control-label" for="inputUser">Username</label>
      <div class="controls">
        <input type="text" id="inputUser" name="inputUser" placeholder="Username">
      </div>
    </div>
    <div class="control-group">
      <div class="controls">
        <button type="submit" class="btn btn-primary">Send Email!</button>
      </div>
    </div>
  </form>

  <?php
  }
  ?>
  • 写回答

1条回答 默认 最新

  • dongnue4923 2013-04-01 00:20
    关注

    you may want to edit you script so it does not have any syntax errors.

    $keyCheck - mysql_num_rows($keyQuery);
    

    change to

    $keyCheck = mysql_num_rows($keyQuery);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 从Freecad中宏下载的DesignSPHysics,出现如下问题是什么原因导致的(语言-python)
  • ¥30 notepad++ 自定义代码补全提示
  • ¥15 MATLAB有限差分法解一维边值问题
  • ¥200 内网渗透测试 横向渗透 Windows漏洞 Windows权限维持
  • ¥15 数据结构图的相关代码实现
  • ¥15 python中aiohttp.client_exceptions.ContentTypeError
  • ¥30 DeepLung肺结节检测生成最大froc值对应的epoch报错
  • ¥15 信号发生器如何将频率调大,步尽值改成10
  • ¥15 keil 5 编程智能家具,风扇台灯开关,人体感应等
  • ¥100 找一名渗透方面的专家