how to change or update password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aries283
    New Member
    • Apr 2010
    • 2

    #1

    how to change or update password

    hi there,
    im having problem to provide "change password" feature. ive tried several coding but nothing can solve it.

    does anyone had experience regarding this problem?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    What have you tried so far?
    Why/how does it not work?
    Did you get any errors? Any unexpected behavior?
    Can we see the code?

    As far as theory goes (which is all I can give you, without any useful info regarding your situation), this should be as simple as:
    1. Have the user submit the old password and the new password. And optionally a password "check" field, to make sure he entered it correctly.
    2. Make sure the old passwords match.
    3. If a "check" field was passed, make sure it matches the new password.
    4. Update the database, using the new password.

    Comment

    • aries283
      New Member
      • Apr 2010
      • 2

      #3
      Originally posted by Atli
      Hey.

      What have you tried so far?
      Why/how does it not work?
      Did you get any errors? Any unexpected behavior?
      Can we see the code?

      As far as theory goes (which is all I can give you, without any useful info regarding your situation), this should be as simple as:
      1. Have the user submit the old password and the new password. And optionally a password "check" field, to make sure he entered it correctly.
      2. Make sure the old passwords match.
      3. If a "check" field was passed, make sure it matches the new password.
      4. Update the database, using the new password.
      the password didnt update.even if ive used the update function.
      here's the code.
      Code:
      <?php require_once('Connections/annajmi.php'); ?>
      <?php
      $colname_Recordset1 = "-1";
      if (isset($_GET['pel_nsb'])) {
        $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['pel_nsb'] : addslashes($_GET['pel_nsb']);
      }
      mysql_select_db($database_annajmi, $annajmi);
      $query_Recordset1 = sprintf("SELECT * FROM pelajar WHERE pel_nsb = '%s'", $colname_Recordset1);
      $Recordset1 = mysql_query($query_Recordset1, $annajmi) or die(mysql_error());
      $row_Recordset1 = mysql_fetch_assoc($Recordset1);
      $totalRows_Recordset1 = mysql_num_rows($Recordset1);
      
      
      if (isset($_POST['hantar'])) { 
      // Handle the form.
      
      
      
      // Create a function for escaping the data. 
      function escape_data ($data) { 
      global $dbc; // Need the connection. 
      if (ini_get('magic_quotes_gpc')) { 
      $data = stripslashes($data); 
      } 
      return mysql_real_escape_string($data, $dbc); 
      } 
      // End of function.
      
      $message = NULL; // Create an empty new variable.
      
      
      // Check for an existing password. 
      if (empty($_POST['katalaluan'])) { 
      $pa = FALSE; 
      $message .= '<p>You forgot to enter your existing password!</p>'; 
      } else { 
      $pa = escape_data($_POST['katalaluan']); 
      }
      
      // Check for a password and match against the confirmed password. 
      if (empty($_POST['katalaluanbaru'])) { 
      $npa = FALSE; 
      $message .= '<p>You forgot to enter your new password!</p>'; 
      } else { 
      if ($_POST['katalaluanbaru'] == $_POST['pastikatalaluan']) { 
      $npa = escape_data($_POST['katalaluanbaru']); 
      } else { 
      $npa = FALSE; 
      $message .= '<p>Your new password did not match the confirmed new password!</p>'; 
      } 
      }
      
      if ($lo && $pa && $npa) { // If everything's OK.
      
      $query = "SELECT * FROM pelajar WHERE (katanama=='$lo' AND katalaluan==katalaluan('$pa') )"; 
      $result = @mysql_query ($query); 
      $num = mysql_num_rows ($result); 
      if ($num == '1') { 
      $row = mysql_fetch_array($result);
      
      // Make the query. 
      $query = "UPDATE pelajar SET katalaluan=katalaluan('$npa') WHERE pel_nsb=$pel_nsb"; 
      $result = @mysql_query ($query); // Run the query. 
      if (mysql_num_rows() == 1) { // If it ran OK.
      
      // Send an email, if desired. 
      echo '<p><b>Your password has been changed.</b></p>';
      
      exit(); // Quit the script.
      
      } else { // If it did not run OK. 
      $message = '<p>Your password could not be changed due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
      } 
      } else { 
      $message = '<p>Your loginName and password do not match our records.</p>'; 
      } 
      mysql_close(); // Close the database connection.
      
      } else { 
      $message .= '<p>Please try again.</p>'; 
      }
      
      } // End of the main Submit conditional.
      
      // Print the error message if there is one. 
      if (isset($message)) { 
      echo '<font color="red">', $message, '</font>'; 
      } 
      ?>
      
      
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <form name="form1" method="post" action="">
        <p>&nbsp;</p>
        <fieldset>
        <legend>Enter your information in the form below:</legend>
        <p><b>Current password:</b>
            <input type="katalaluan" name="katalaluan" size="20" maxlength="20" />
        </p>
        <p><b>New password:</b>
            <input type="katalaluanbaru" name="katalaluanbaru" size="20" maxlength="20" />
        </p>
        <p><b>Confirm New password:</b>
            <input type="pastikatalaluan" name="pastikatalaluan" size="20" maxlength="20" />
        </p>
        </fieldset>
        <div align="center">
          <input type="submit" name="submit" value="change My password" />
        </div>
        <?php
      mysql_free_result($Recordset1);
      ?>

      Comment

      Working...