change password and session.php
Posted: Thu Oct 27, 2011 2:52 am
not sure if people already have this but im going to post this code anyway.
what this basically does is you log into your account and click change password, you type in your old password, and then new password and then you repeat your new password. and it changes the password in the DB. first make a new php document and call it changepassword.php and put this in.
and it first makes sure that your old password matches your current password and then it checks to make sure your new passwords match then it changes it, and you wont be able to log in with your old password anymore you can now use the new password.
and another thing i use session.php which holds all my player info, to do this just make a new php document and call it session.php and put this into it
let me know what you think of this code.
coming next email activation...
what this basically does is you log into your account and click change password, you type in your old password, and then new password and then you repeat your new password. and it changes the password in the DB. first make a new php document and call it changepassword.php and put this in.
Code: Select all
<?php
include 'session.php';
include 'connect.php';
if ($_POST['submit'])
{
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
$queryget = mysql_query("SELECT password from players where name='$player'") or die("Could not get password field");
$row = mysql_fetch_assoc($queryget);
$oldpassworddb = $row['password'];
if ($oldpassword==$oldpassworddb)
{
if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("
UPDATE players SET PASSWORD='$newpassword' WHERE name='$player'");
session_destroy();
die("Your password has been changed <a href='login.php'>Login</a>");
}
else
die("The new passwords don't match!");
}
else
die("Old password doesn't match!");
}
else
{
echo "
<form action='changepassword.php' method='POST'>
Old Password: <input type='text' name='oldpassword'><br>
New Password: <input type='password' name='newpassword'><br>
Repeat New Password: <input type='password' name='repeatnewpassword'><br>
<input type='submit' name='submit' value='Change Password'>
</form>
";
}
?>
and another thing i use session.php which holds all my player info, to do this just make a new php document and call it session.php and put this into it
Code: Select all
<?php
session_start();
include 'connect.php';
if (isset($_SESSION['player']))
{
$player=$_SESSION['player'];
}
else
{
echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
?>
coming next email activation...