SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    tio
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change passwords

    Hi there ...does anybody know or have the code on how to change passwords.its for my site and would be grateful if anybody could help!

  2. #2
    SitePoint Enthusiast gnome's Avatar
    Join Date
    Jun 2002
    Location
    in a book
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how are you checking the username and passwords?
    "Well, you know boys, a nuclear reactor is a lot like a woman.
    You just have to read the manual and press the right button."
    --Homer J Simpson

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    tio
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gnome
    how are you checking the username and passwords?
    Im checking and comparing them against the name in the database that was supplied in the first instance

  4. #4
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are the passwords encrypted?

    what you could do is provide some sort of verification like letting the user type in an old password. Then if that pass matches the one with the pass in the database, grab the new password and encrypt it then update the table using mysql_query("UPDATE...)


    old pass: ____
    new pass: ____
    verify new pass: ____

    i hope this helps

    -rsdl
    Last edited by rsdl; Mar 10, 2003 at 15:14.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    tio
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rsdl
    are the passwords encrypted?

    -rsdl
    yes by md5 encryption

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    tio
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jermaine
    yes by md5 encryption
    thanx nacho man

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a suggestion on how to change the password:
    PHP Code:
    <?php?>
    <form method="post" action="changePassword.php" />
    Username: <input type="text" name="username" /><br />
    Old password: <input type="password" name="oldPassword" /><br />
    New password: <input type="password" name="newPassword" /><br />
    Confirm new password: <input type="password" name="confirmNewPassword" /><br />
    </form

    <?php
    // changePassword.php
    $sql "SELECT COUNT(*)
              FROM tbl
             WHERE username ='" 
    $_POST['username'] . "'
               AND password ='" 
    md5($_POST['oldPassword'] . "'";
    $result mysql_query($sql) or die(mysql_error());
    $count mysql_fetch_array($result);
    if(
    $count === 1)) {
        if(
    $_POST['newPassword'] === $_POST['confirmNewPassword']) {
            
    $sql "UPDATE tbl
                       SET password ='" 
    md5($_POST['newPassword']) . "'
                     WHERE password ='" 
    md5($_POST['oldPassword']) . "'";
            
    $result mysql_query($sql) or die(mysql_error());
            
    $count mysql_affected_rows($result);
            if(
    $count === -1) {
                echo 
    'Something went wrong while changing the password in the database';
            } else {
                echo 
    'Password is updated';
            }
        } else {
            echo 
    "The new passwords didn't match";
        }
    } else {
        echo 
    'The username or old password is incorrect.';
    }
    ?>
    This might give you a start on how this work.

    -Helge


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
  •