Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Change password script

    Hi everyone!

    I am building a user profile page. My database has been set up. I want to let users to change their pass word in their profile. Can anyone provide a PHP script for doing this? Thanks!

    This is the information:
    Table Name: members
    Columns

    +------------+----------+-----------+
    | member_id | login | passwd |
    +------------+----------+-----------+
    | 1 | testing | testing |
    +------------------------------------+

    Thats the structure.

    Basicly I need a form to change the password for the member.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    This is a work request and should be moved to that forum.

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Its not tho, its a simple script. :P

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts

    Slavery is illegal

    Yes, it is simple... and not written yet. Someone may write it for you out of the goodness of their heart, but I call that slavery. This forum is not here for you to get free work out of people, it's here for you to learn how to code PHP. It's annoying to see you begging.

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I currently have this:

    PHP Code:
    <?
    session_start
    ();
    session_register("session");
    //if(!isset($session['userid'])){
    //echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";
    //exit;
    //}
    // This is displayed if all the fields are not filled in
    $empty_fields_message "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back";
    // Convert to simple variables 
    $password1 $_POST['password1']; 
    $password2 $_POST['password2'];
    if (!isset(
    $_POST['password1'])) {
    ?>
    <h2>Change password! <? echo $_SESSION['email_address']; ?></h2>
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
        <p class="style3"><label for="password1"">New password:</label>
        <input type="password" title="Please enter a password" name="password1" size="30"></p>
        <p class="style3"><label for="password2">Re-enter Password:</label>
        <input type="password" title="Please re-enter password" name="password2" size="30"></p>
        <p style="stext-align:left"><label for="submit">&nbsp</label>
        <input type="submit" value="Change" class="submit-button"/></p>
    </form>
    <?php
    }
    elseif (empty(
    $password1) || empty($password2))  {
        echo 
    $empty_fields_message;
    }
    else {
    include 
    'includes/connection.php'
    $db_password1=md5(mysql_real_escape_string($password1));
    //Setting flags for checking
    $status "OK";
    $msg="";
    if ( 
    strlen($password1) < or strlen($password1) > 10 ){
    $msg=$msg."Password must be more than 3 characters in length and maximum 10 characters in length<BR>";
    $status"NOTOK";}     
    if (
    strcmp$password1,$password2 ) !=0){
    $msg=$msg."Both passwords do not match<BR>";
    $status"NOTOK";}     
    if(
    $status<>"OK"){ 
    echo 
    "<font face='Verdana' size='2' color=red>$msg</font><br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
    }else{ 
    // if all validations are passed.
    if(mysql_query("update users set password='$db_password1' where userid='$session[userid]'")){
    echo 
    "<font face='Verdana' size='2' ><center>Thanks <br> Your password changed successfully. Please keep changing your password for better security</font></center>"$password1;
    }
    }
    }

  • #6
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    i think this should get you started
    PHP Code:

    $form 
    =
    <<<EOF
    <form action="" method="POST">
    <input type="hidden" name="member" value="1" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    EOF;


    if (isset(
    $_POST['chpass'])) {
     
    $sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
    $result mysql_query($sql);
    while (
    $row mysql_fetch_assoc($result)) {
     
    $pass $row['passwd'];
    }

    if (
    $_POST['oldpass'] == $pass) {
     
    mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
    }
    print_r($_POST);
    }
    else {
    echo 
    $form;


  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Ok, is that the whole thing or just part of it, also what do the <<<EOF EOF; tags mean?

  • #8
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Quote Originally Posted by bucket View Post
    Ok, is that the whole thing or just part of it, also what do the <<<EOF EOF; tags mean?
    i just use them to write HTML a bit simpler.

    this script, not tested, is supposed to on $_POST being set first select members password from members table.

    then it checks weather that password is same as old password user used, and if that password is the same, it will update member with new password.

    i inserted member_id here manually but if you have SESSION where that member ID is set, or any other way you can get current member id you can simply do this to add it to the form

    PHP Code:

    if (!empty($_SESSION['member_id'])) {
     
    $member $_SESSION['member_id'];
    }
    else {
     
    $member FALSE;
    }


    $form =
    <<<EOF
    <form action="" method="POST">
    <input type="hidden" name="member" value="$member" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    EOF; 
    and then in the script you can check weather $member is set

    PHP Code:
    if (isset($_POST['chpass'])) {

    if (
    $_POST['member'] != "FALSE") {
     
    $sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
    $result mysql_query($sql);
    while (
    $row mysql_fetch_assoc($result)) {
     
    $pass $row['passwd'];
    }

    if (
    $_POST['oldpass'] == $pass) {
     
    mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
    }
    print_r($_POST);
    }
    }
    else {
    echo 
    "FALSE MEMBER";
    }
    else {
    echo 
    $form;


  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Ok.

    So the 2 things are:

    Form:
    PHP Code:
    <?php
    if (!empty($_SESSION['member_id'])) {
     
    $member $_SESSION['member_id'];
    }
    else {
     
    $member FALSE;
    }
    ?>

    <form action="" method="POST">
    <input type="hidden" name="member" value="$member" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    The script:
    PHP Code:
    <?php
    include 'db.php';

    if (isset(
    $_POST['chpass'])) {

    if (
    $_POST['member'] != "FALSE") {
     
    $sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
    $result mysql_query($sql);
    while (
    $row mysql_fetch_assoc($result)) {
     
    $pass $row['passwd'];
    }

    if (
    $_POST['oldpass'] == $pass) {
     
    mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
    }
    print_r($_POST);
    }
    }
    else {
    echo 
    "FALSE MEMBER";
    }
    else {
    echo 
    $form;
    }  
    ?>
    Last edited by bucket; 08-27-2009 at 05:53 PM.

  • #10
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Quote Originally Posted by bucket View Post
    Ok.

    So the 2 things are:

    Form:
    PHP Code:
    <?php
    if (!empty($_SESSION['member_id'])) {
     
    $member $_SESSION['member_id'];
    }
    else {
     
    $member FALSE;
    }
    ?>

    $form =
    <<<EOF
    <form action="" method="POST">
    <input type="hidden" name="member" value="$member" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    EOF;
    no form is like this

    PHP Code:
    <?php
    if (!empty($_SESSION['member_id'])) {
     
    $member $_SESSION['member_id'];
    }
    else {
     
    $member FALSE;
    }


    $form =
    <<<EOF
    <form action="" method="POST">
    <input type="hidden" name="member" value="$member" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    EOF; 
    ?>

  • #11
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Ok, and the form goes to what page?

  • #12
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    The form page shows up as a blank page.

  • #13
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Quote Originally Posted by bucket View Post
    The form page shows up as a blank page.
    form is just a variable now, you need to echo it in order to see it. i made this script to be just in one page, but if you made it into 2 pages then you need to echo $form variable on page1, and add form action to page2

    something like this

    PHP Code:
    <?php
    if (!empty($_SESSION['member_id'])) {
     
    $member $_SESSION['member_id'];
    }
    else {
     
    $member FALSE;
    }


    $form =
    <<<EOF
    <form action="PAGE2SCRIPT.PHP" method="POST">
    <input type="hidden" name="member" value="$member" />
    <p>Old password: <input type="password" name="oldpass" /></p>
    <p><input type="password" name="newpass" /></p>
    <inpu type="submit" name="chpass" />
    </form>
    EOF;

    echo 
    $form;
    ?>
    and then in PAGE2SCRIPT.PHP you need to change your if control structure to similar like this....

    PHP Code:
    <?php
    include 'db.php';

    if (isset(
    $_POST['chpass'])) {

        if (
    $_POST['member'] != "FALSE") {
            
    $sql = ("SELECT passwd FROM members WHERE member_id = '".$_POST['member']."'");
            
    $result mysql_query($sql);
        
            while (
    $row mysql_fetch_assoc($result)) {
                
    $pass $row['passwd'];
            }

            if (
    $_POST['oldpass'] == $pass) {
             
    mysql_query("UPDATE members SET passwd = '".$_POST['newpass']."' where member_id = '".$_POST['member']."'");
            }
            
    ##THIS IS USED JUST FOR TESTING PURPOSES
            ##YOU CAN UNCOMMENT IT TO SEE WHAT $POST
            ##VARS ARE SET
            ##print_r($_POST);
        
    }
        else {
            echo 
    "FALSE MEMBER";
        } 
    }
    ?>

  • #14
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    When I try and change the pass it says:

    Code:
    Notice: Undefined variable: pass in /home/admin/website.com/admin/change-pass2.php on line 18
    Line 18 is:
    PHP Code:
     if ($_POST['oldpass'] == $pass) { 

  • #15
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Any luck fixing it?


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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