change password and session.php

Place to place any code snippets, completed games, or even uncompleted games for IR users to use.
Post Reply
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

change password and session.php

Post by dust1031 »

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.

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 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

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);
?>
let me know what you think of this code.

coming next email activation...
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: change password and session.php

Post by Ark »

Pretty nice! i'm interested in the next tutorial, keep it up!
Orgullo Catracho
dust1031
Posts: 92
Joined: Fri Jul 22, 2011 3:38 am

Re: change password and session.php

Post by dust1031 »

thanks! i might hold off on the email activation, proving more difficult than i thought. i'm working on something else right now though.
Post Reply

Return to “Code Sharing”