What's new

Help Php gadz pasok i need ur help!

O s l o

Forum Guru
Elite
Joined
Mar 6, 2020
Posts
2,272
Solutions
9
Reaction
5,025
Points
1,201
1634475507733.png


1634475539504.png


forget-password_sq.php
PHP:
<?php
session_start();
?>
<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
      <title>Send Reset Password Link with Expiry Time in PHP MySQL</title>
       <!-- CSS -->
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
       <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
       <link rel="stylesheet" href="css/fpws.css">
   </head>
   <style>
  body{
    background-image: url('images/bglogin.jpg');
    background-image: no-repeat;
    background-size: cover;
  }
</style>
   <body>
      <div class="container">
          <div class="card">
            <div class="card-header text-center">
            <h1>Forgot Password</h1>
            Enter your email address
            </div>
            <span class="success" align="center" style="background:lightgreen">
              <?php
              if(isset($_SESSION['email']))
              {
                echo $_SESSION['email'];
                unset($_SESSION['email']);
                
              }
              
              ?>
              
            </span>
            
            <span align="center" style="background-color: #FFD2D2; color:white;" class="error">
            
              <?php
              if(isset($_SESSION['error']))
              {
                echo $_SESSION['error'];
                unset($_SESSION['error']);
              }
              ?>
              </span>
            <div class="card-body">
              <form action="password-reset-tokensqa.php" method="post">
              <div class="form-group">
                  <input type="email" name="email" class="form-control" id="email" placeholder=" ex. juan@gmail.com" aria-describedby="emailHelp"required>
                  <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
                </div>
                <div class="form-group">
                <label for="question"><b>Security Question </b></label>
                        <select id="" name="question" class="form-control  select1  " required >
                  
                  <option value="<?php echo isset($meta['question']) ? $meta['question']: '' ?>"><?php echo isset($meta['question']) ? $meta['question']: '' ?></option>
                  <option value="What is your date of birth?">What is your date of birth? </option>
                  <option value="What was your favorite school teacher’s name?">What was your favorite school teacher’s name? </option>
                  <option value="What’s your favorite movie?">What’s your favorite movie? </option>
                  <option value="What was your first car?">What was your first car? </option>
                  <option value="What city were you born in?">What city were you born in? </option>
                  
                
                </select>
                </div>
                <div class="form-group">
                      <label for="password"><b>Answer</b>  </label>
                <input type="text" name="ans" id="" class="form-control" value="<?php echo isset($meta['ans']) ? $meta['ans']: '' ?>"  required>
                    </div>
                <input type="submit" name="password-reset-tokensqa" class="btn btn-primary">
                <br><br>
                <span class="lg">
                  Already have an account? <br> <a href="logins.php"> <small>Login here </small> </a> | <a href="forget-password.php"> <small>Reset PW Email</small> </a>
                </span>
              </form>
            </div>
          </div>
      </div>
              
   </body>
</html>

password-reset-tokensqa.php
PHP:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
session_start();
if(isset($_POST['password-reset-tokensqa']) && $_POST['email'])
{
  include 'db_connect.php';
    
    $email = $_POST['email'];
    $password = 'password';
 
    $result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
 
    $row= mysqli_fetch_array($result);
 
  if($row)
  {
    
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );
 
    $expDate = date("Y-m-d H:i:s",$expFormat);
 
    $update = mysqli_query($conn,"UPDATE users set  password ='" . md5($password) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "'");
 
    $link = "<a href='cms/reset-password.php?key=".$email."&token=".$token."'>Click to Reset password</a>";
 
    require_once('fpwvendor/autoload.php');
 
    $mail = new PHPMailer(true);
 
    $mail->CharSet =  "utf-8";
    $mail->IsSMTP();
    // enable SMTP authentication
    $mail->SMTPAuth = true;                 
    // GMAIL username
    $mail->Username = "qq@gmail.com";
    // GMAIL password
    $mail->Password = "qq";
    $mail->SMTPSecure = "ssl"; 
    // sets GMAIL as the SMTP server
    $mail->Host = "smtp.gmail.com";
    // set the SMTP port for the GMAIL server
    $mail->Port = "465";
    $mail->From='qq@gmail.com';
    $mail->FromName='xx : Courier ';
    $mail->AddAddress($email);
    $mail->Subject  =  'Reset Password';
    $mail->IsHTML(true);
    $mail->Body    = 'Click on this Link to Reset Password '.$link.'';
    if($mail->Send())
    {
      $_SESSION['email']="We've sent you a reset password in your gmail account - ".$email."" ;
      header( "refresh:1;url=forget-password_sq.php" );
    
    }
    else
    {
      echo "Mail Error - >".$mail->ErrorInfo;
    }
  }else{
    $_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
    header( "refresh:1;url=forget-password_sq.php" );
  }
}
?>
 

Attachments

bale gusto ko po sana mag labas din ng error kung mali yong security question at answer.
 
tama ba yong ganyan na nilagay q dati?
PHP:
if(isset($_POST['Pásswørd-reset-tokensqa']) && $_POST['email'] && $_POST['question'] && $_POST['ans'] )
 
tama ba yong ganyan na nilagay q dati?
PHP:
if(isset($_POST['Pásswørd-reset-tokensqa']) && $_POST['email'] && $_POST['question'] && $_POST['ans'] )
PHP:
$email = $_POST['email'];
$Pásswørd = 'Pásswørd';
$ques = $_POST['question'];
$ans = $_POST['ans'];
 
eto gagalawin ko paba?
PHP:
$result = mysqli_query($conn,"SELECT * FROM users WHERE email='" . $email . "'");
eto ganto?
PHP:
$update = mysqli_query($conn,"UPDATE users set  Pásswørd ='" . md5($Pásswørd) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "' ,question ='" . $ques . "' , ans ='" . $ans . "' ");
 
eto ganto?
PHP:
$update = mysqli_query($conn,"UPDATE users set  Pásswørd ='" . md5($Pásswørd) . "', reset_link_token='" . $token . "' ,exp_date='" . $expDate . "' WHERE email='" . $email . "' ,question ='" . $ques . "' , ans ='" . $ans . "' ");
sa part na to saan ako mag-aano if ever para macheck paps? yang checker na sinasabe mo.
PHP:
if($mail->Send())
    {
      $_SESSION['email']="We've sent you a reset Pásswørd in your gmail account - ".$email."" ;
      header( "refresh:1;url=forget-password_sq.php" );
    
    }
    else
    {
      echo "Mail Error - >".$mail->ErrorInfo;
    }
  }else{
    $_SESSION['error']="Invalid Email Address Please check carefully ".$email."";
    header( "refresh:1;url=forget-password_sq.php" );
  }
 
if want mo pati ung security question and answers is na vavalidatem i think dapat nasa DB mo iyon.
 
Code:
  if($row)
  {
    // HERE
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );

dyan mo ilagay yung checker sa may // HERE

fetch answer in db where question == question_sent
if no row return invalid question
if may row gawin mo if db_rows != answer_sent -> return invalid answer
 
Code:
  if($row)
  {
    // HERE
     $token = md5($email).rand(10,9999);
 
     $expFormat = mktime(
     date("H"), date("i"), date("s"), date("m") ,date("d")+1, date("Y")
     );

dyan mo ilagay yung checker sa may // HERE

fetch answer in db where question == question_sent
if no row return invalid question
if may row gawin mo if db_rows != answer_sent -> return invalid answer
ha?
 

Similar threads

Back
Top