Search
Left Quote    I have not failed. I've just found 10,000 ways that won't work.
- Thomas Alva Edison    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Change Password Add on
  This user is offline  gravy
  Subject: "Change Password Add on" Posted: @ 3:03 pm on Jul 08 2007   

Member #: 294
Rank: User - (63)
Since: 03/07/07
Posts: 66
From: MN

wondering how difficult this can be, a form, and a query right?


Photo Hosting Scripts? It's what I do....
    Viewed: 10,316 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Change Password Add on" Posted: @ 3:26 pm on Jul 10 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

essentially, yes. you'd also want to make sure the user is logged in and make them enter their old password to make sure they didn't just forget to logout and someone else is changing their password...




please note that the above post is likely made up in its entirety.

    Viewed: 10,296 Times | Reply to This | To top
  This user is offline  WintersDance
  Subject: "re: Change Password Add on" Posted: @ 5:18 am on Jul 11 2007    

Member #: 353
Rank: User - (27)
Since: 06/19/07
Posts: 36
From: California

Try something like this:

Change Form:

Code:


<form action="& lt;? echo $PHP_SELF; ?>" method=post>
<input type="hid den" name="use rname" value="&l t;?php echo $_SESSION['use rname']; ?>"> ;
<table> <tr><t d colspan=2>&l t;p>Change Password</td ></tr>
<tr><t d><p>O ld password:</t d>
<td><i nput type="pas sword" name="old _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d><p>N ew password:</t d>
<td><i nput type="pas sword" name="new _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d colspan=2>&l t;input name="sub mit" type="sub mit" value="Ch ange password" >
</td>< /tr>
</table>< br /> </form>



and in your header:

Code:

function change_member_p assword($userna me, $old_password, $new_password)< br /> {
//First check if username & password match in database.
$result = mysql_query(&q uot;SELECT * from members WHERE username = '$username' and user_password = '".md5($ _POST['old_pas sword']).&quo t;'"); if (!$result)
//return false;
echo "<p style=\" color:white\& quot;>cannot match at database" ;
//exit;

if (mysql_num_rows ($result)>0)
{
// if the old password is right, change their password to new_password and return true
$result = mysql_query(&q uot;UPDATE members SET user_password = '".md5($ _POST['new_pas sword']).&quo t;' where username = '$username'& quot;);
if (!$result) {
echo "Password could not be updated";
} // not changed
else {
echo "Password successfully changed";
} // changed successfully
}
else {
echo "Old Password not correct." ;
} // Wrong old password
}

if(isset($HTTP _POST_VARS['su bmit']))
{
change_member_p assword($_POST[ 'username'], $_POST['old_pa ssword'], $_POST['new_pa ssword']);
}



It would prolly make sense to make a page called "change_p assword.php&qu ot; and have all this code on that one page. This way you don't need to change any other pages.

So full page would look like this:

Code:

<?php
session_start() ;
include(" includes.php&q uot;);
header_page();< br />
function change_member_p assword($userna me, $old_password, $new_password) //change password script
{
//First check if username & password match in database.
$result = mysql_query(&q uot;SELECT * from members WHERE username = '$username' and user_password = '".md5($ _POST['old_pas sword']).&quo t;'"); if (!$result)
echo "<p style=\" color:white\& quot;>cannot match at database" ;

if (mysql_num_rows ($result)>0)
{
// if the old password is right, change their password to new_password and return true
$result = mysql_query(&q uot;UPDATE members SET user_password = '".md5($ _POST['new_pas sword']).&quo t;' where username = '$username'& quot;);
if (!$result) {
echo "Password could not be updated";
} // not changed
else {
echo "Password successfully changed";
} // changed successfully
}
else {
echo "Old Password not correct." ;
} // Wrong old password
}

if(isset($HTTP _POST_VARS['su bmit'])) //make sure page was submitted
{
change_member_p assword($_POST[ 'username'], $_POST['old_pa ssword'], $_POST['new_pa ssword']);
}

// Main Content
?>

<form action="& lt;? echo $PHP_SELF; ?>" method=post>
<input type="hid den" name="use rname" value="&l t;?php echo $_SESSION['use rname']; ?>"> ;
<table> <tr><t d colspan=2>&l t;p>Change Password</td ></tr>
<tr><t d><p>O ld password:</t d>
<td><i nput type="pas sword" name="old _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d><p>N ew password:</t d>
<td><i nput type="pas sword" name="new _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d colspan=2>&l t;input name="sub mit" type="sub mit" value="Ch ange password" >
</td>< /tr>
</table>< br /> </form>
<?php
footer();
?>



Just pretty up the output to match your site. Add confirmations and prolly add something to double check that the form fields are not empty. But this should work for you.




wintersdance |     Viewed: 10,283 Times | Reply to This | To top
  This user is offline  gravy
  Subject: "re: Change Password Add on" Posted: @ 11:40 pm on Jul 14 2007    

Member #: 294
Rank: User - (63)
Since: 03/07/07
Posts: 66
From: MN

  WintersDance said...

< i> Try something like this:

Change Form:
<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;
<form action="& lt;? echo $PHP_SELF; ?>" method=post>
<input type="hid den" name="use rname" value="&l t;?php echo $_SESSION['use rname']; ?>"> ;
<table>
<tr><t d colspan=2>&l t;p>Change Password</td ></tr>
<tr><t d><p>O ld password:</t d>
<td><i nput type="pas sword" name="old _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d><p>N ew password:</t d>
<td><i nput type="pas sword" name="new _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d colspan=2>&l t;input name="sub mit" type="sub mit" value="Ch ange password" >
</td>< /tr>
</table>
</form>



and in your header:
<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;
function change_member_p assword($userna me, $old_password, $new_password)
{
//First check if username & password match in database.
$result = mysql_query(&q uot;SELECT * from members WHERE username = '$username' and user_password = '".md5($ _POST['old_pas sword']).&quo t;'";
if (!$result)
//return false;
echo "<p style=\" color:white\& quot;>cannot match at database" ;
//exit;

if (mysql_num_rows ($result)>0)
{
// if the old password is right, change their password to new_password and return true
$result = mysql_query(&q uot;UPDATE members SET user_password = '".md5($ _POST['new_pas sword']).&quo t;' where username = '$username'& quot;
if (!$result) {
echo "Password could not be updated";
} // not changed
else {
echo "Password successfully changed";
} // changed successfully
}
else {
echo "Old Password not correct." ;
} // Wrong old password
}

if(isset($HTTP _POST_VARS['su bmit']))
{
change_member_p assword($_POST[ 'username'], $_POST['old_pa ssword'], $_POST['new_pa ssword']);
}



It would prolly make sense to make a page called "change_p assword.php&qu ot; and have all this code on that one page. This way you don't need to change any other pages.

So full page would look like this:
<BR><f ont size=1><u >Code:</u ><BR>& lt;div name="div _box" class="di vCode"> ;
<?php
session_start() ;
include(" includes.php&q uot;
header_page();

function change_member_p assword($userna me, $old_password, $new_password) //change password script
{
//First check if username & password match in database.
$result = mysql_query(&q uot;SELECT * from members WHERE username = '$username' and user_password = '".md5($ _POST['old_pas sword']).&quo t;'";
if (!$result)
echo "<p style=\" color:white\& quot;>cannot match at database" ;

if (mysql_num_rows ($result)>0)
{
// if the old password is right, change their password to new_password and return true
$result = mysql_query(&q uot;UPDATE members SET user_password = '".md5($ _POST['new_pas sword']).&quo t;' where username = '$username'& quot;
if (!$result) {
echo "Password could not be updated";
} // not changed
else {
echo "Password successfully changed";
} // changed successfully
}
else {
echo "Old Password not correct." ;
} // Wrong old password
}

if(isset($HTTP _POST_VARS['su bmit'])) //make sure page was submitted
{
change_member_p assword($_POST[ 'username'], $_POST['old_pa ssword'], $_POST['new_pa ssword']);
}

// Main Content
?>

<form action="& lt;? echo $PHP_SELF; ?>" method=post>
<input type="hid den" name="use rname" value="&l t;?php echo $_SESSION['use rname']; ?>"> ;
<table>
<tr><t d colspan=2>&l t;p>Change Password</td ></tr>
<tr><t d><p>O ld password:</t d>
<td><i nput type="pas sword" name="old _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d><p>N ew password:</t d>
<td><i nput type="pas sword" name="new _password" ; size=16 maxlength=16> ;</td>< ;/tr>
<tr><t d colspan=2>&l t;input name="sub mit" type="sub mit" value="Ch ange password" >
</td>< /tr>
</table>
</form>

<?php
footer();
?>



Just pretty up the output to match your site. Add confirmations and prolly add something to double check that the form fields are not empty. But this should work for you.


Awesome dude i will definately use some of this to get the job done, I appreciate your coding dude!




Photo Hosting Scripts? It's what I do....

    Viewed: 10,238 Times | Reply to This | To top
  This user is offline  abhi
  Subject: "re: Change Password Add on" Posted: @ 10:04 pm on Jul 30 2007    
Member #: 379
Rank: User - (19)
Since: 07/30/07
Posts: 19
From: Michigan

Can anyone give me the code of how to register on a website if some one is not registered code for register.php... ..also once the user registers with a valid e-mail address an authentication e-mail shd be sent and once he clicks on that his username and password shd get activated....!! !




abhishekitty@ya
hoo.com |     Viewed: 10,043 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank