1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Reset password code not working? Can anyone here help me to fix this?

Discussion in 'PHP' started by mayank jain, Jun 10, 2018.

  1. mayank jain

    mayank jain New Member

    Joined:
    Jun 4, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hello there I am trying to update the password but whenever I execute this code it gives an error message. Is anyone here can check this code tell me how to fix this..
    What I did i created php code for forgot password using token and email and successfully can run the code. But whenever I run this code below it doesn't execute the code.
    I am new in programming so can anyone here help me this code.
    PHP:
    <?php
        
    if (isset($_GET["token"]) && isset($_GET["email"])) {
            include(
    "config.php");
            
            
    $password $con->real_escape_string($_POST['password']);
            
    $cPassword $con->real_escape_string($_POST['cPassword']);
                
            
    $data $con->query("SELECT id FROM users WHERE email='$email' AND token='$token'");

            if (
    $data->num_rows 0) {
                
                
                
    $password $con->real_escape_string($_POST['password']);
                
    $cPassword $con->real_escape_string($_POST['cPassword']);
                if (
    $password != $cPassword)
                
    $msg "Please check your password again!";
            else{

                
    $hashedPassword password_hash($passwordPASSWORD_BCRYPT);

                
    $con->query("UPDATE users SET password = '$hashedPassword', token = '' WHERE email='$email'");

                echo 
    "Your new password is: $password";
                
            }
                    else {
                echo 
    "Please check your link!";
            }
            }
        } else {
            
    header("Location: login.php");
            exit();
        }
            
    ?>
    And the HTML is as follows
    HTML:
    <html>
    <body>
    <form class="login100-form validate-form" method="post" action="resetPassword.php">
                            <span class="login100-form-logo">
                                <img src="images/logo.png" alt="logo"></img>
                             </span>
                             <span class="login100-msg"><br>
                        <?php if ($msg != "") echo $msg . "<br>" ?></span>
                        <span class="login100-form-title p-b-34 p-t-27">
                           Update Your Password
                        </span>
                        <div class="wrap-input100 validate-input" data-validate = "Enter password">
                            <input class="input100" type="password" name="password" placeholder="Enter Password">
                            <span class="focus-input100" data-placeholder="&#xf207;"></span>
                        </div>
                        <div class="wrap-input100 validate-input" data-validate = "Enter cPassword">
                            <input class="input100" type="text" name="cPassword" placeholder="Enter Password Again">
                            <span class="focus-input100" data-placeholder="&#xf207;"></span>
                        </div>
                        
                        <div class="container-login100-form-btn">
                            <button class="login100-form-btn" type="submit" name="forgotPass">
                                Update Password
                            </button>
                        </div>
                    
                      
                    </form>
    
    </body>
    </html>
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,323
    Likes Received:
    376
    Trophy Points:
    83
    $token variable is never assigned the $_GET token.
     
  3. mayank jain

    mayank jain New Member

    Joined:
    Jun 4, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Sir thanks for your reply but here I am trying to take the token variables from url itself.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,323
    Likes Received:
    376
    Trophy Points:
    83
    For that you have to assign the variable like
    Code:
    $token = $_GET["token"];
    or rather
    Code:
    $token = $con->real_escape_string($_GET['token']);
     

Share This Page