SitePoint Sponsor

User Tag List

Results 1 to 25 of 60

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2013
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    weird issue PASSWORD RESET!

    Hi, i m trying to write a code for resetting password. I want this code to show in on the log in page (and the user should be able to open it without being logged in),,, however the problem i am facing is, whenever i open my recover form thus, localhost/pass.php , my recover form has a field for email and security question, ) it just shows the login page, which is localhost/login.php... i'm stuck on this now for days, and nothing seems to improve...


    and just to make helping easier, i'm planning to implement a recover function thus:
    1. when the user clicks on forgot password on localhost/login.php without already being logged in, it should take them to a page,
    pass.php (displaying an email and security question)...

    2.and when the users enter both( confirm if they exist in the sql table), then redirect to another form reset.php which shows two fields for "Enter new password" and "Confirm password", and when user enters both, his password is updated in the database...

    Pass.php has a template pass_form.php
    and reset.php has a template reset_form.phpp


    PHP Code:
    //code for pass.php:  
     
     
    <?php
     
     
      
    // configuration
        
    require("../includes/config.php"); 
        
         if (
    $_SERVER["REQUEST_METHOD"] == "POST")
      {
         if (empty(
    $_POST["forgotpassword"]))
         
    apologize("Please enter email address.");
         
         if (empty(
    $_POST["security"]))
         
    apologize("Please enter your security key.");
         
        
    $email $_POST["forgotpassword"]; 
        if(!(
    filter_var($emailFILTER_VALIDATE_EMAIL)))
        
         
    apologize("Please enter a valid email such as [email]example@domain.com[/email]");
         
         
    //check if email and securitykey exist in users table
         
        
    $checkquery("SELECT id, security FROM users WHERE email = ?"$_POST["forgotpassword"]);
        if (
    $check === false)
        
    apologize("No such user in database");
      
       
        
    render("reset.php", ["title" => "Reset Password""check" => $check]);
        
      }
      
      else  
    render("login_form.php", ["title" => "Login"]);
      
      
      
    ?>
    3. another problem is when i log in, and then i open localhost/pass.php, it always keeps on rendering the above template called login_form.php( which is linked to the controller login.php...) instead of displaying the pass_form.php
    template...
    HTML Code:
    ///  pass_form.php  is as follows:
     
    <form action="pass.php" method="post">
        <fieldset>
            <div class="control-group">
                <input name="forgotpassword" placeholder="Email" type="text"/>
            </div>
            <div class="control-group">
                <input name="security" placeholder="Security Keyword" type="text"/>
            </div>
            <div class="control-group">
                <button type="submit" class="btn">Reset</button>
            </div>
        </fieldset>
    </form>




    RENDER() is a function as follows


    PHP Code:
    function render($template$values = [])
        {
            
    // if template exists, render it
            
    if (file_exists("../templates/$template"))
            {
                
    // extract variables into local scope
                
    extract($values);
     
                
    // render header
                
    require("../templates/header.php");
     
                
    // render template
                
    require("../templates/$template");
     
                
    // render footer
                
    require("../templates/footer.php");
            }
     
            
    // else err
            
    else
            {
                
    trigger_error("Invalid template: $template"E_USER_ERROR);
            } 
    Last edited by cpradio; Feb 27, 2013 at 12:25. Reason: Added [php] and [html] tags


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •