Change Pincode


Change Pincode:

by request,
save this as chpin.php
PHP Code
  1. <?php
  2. include("config.php");
  3. if($logged[username])
  4. {
  5. switch($_GET[page])
  6. {
  7. default:
  8. echo ("
  9. <strong>Change Pincode:</strong>
  10. <form method=\"post\" action=\"?page=change\">
  11. <table>
  12. <tr>
  13. <td>Current Pincode:</td>
  14. <td><input name=\"current\" type=\"password\"></td>
  15. </tr>
  16. <tr>
  17. <td>New Pincode:</td>
  18. <td><input name=\"new\" type=\"password\"></td>
  19. </tr>
  20. <tr>
  21. <td></td>
  22. <td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
  23. </tr>
  24. </table>
  25. </form>
  26. ");
  27. break;
  28.  
  29. case 'change':
  30. $current = "$_POST[current]";
  31. $new = "$_POST[new]";
  32.  
  33. $sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
  34. $profile = mysql_fetch_array($sql);
  35.  
  36. if($current == NULL || $new == NULL)
  37. {
  38. die ("All fields are required.");
  39. }
  40. if($current != $profile[pincode])
  41. {
  42. die ("Your current password does not match the posted password.");
  43. }
  44. else
  45. {
  46. $sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
  47. echo ("Pincode successfully changed.");
  48. }
  49. break;
  50. }
  51. }
  52. else
  53. {
  54. echo ("Please login.");
  55. }
  56. ?>

Define:
PHP Code
  1. <?php
  2. include("config.php");
  3. if($logged[username])
  4. {
  5. switch($_GET[page])
  6. {

Includes our database connection, checks if user is logged in, and makes it ?page=

PHP Code
  1. <strong>Change Pincode:</strong>
  2. <form method=\"post\" action=\"?page=change\">
  3. <table>
  4. <tr>
  5. <td>Current Pincode:</td>
  6. <td><input name=\"current\" type=\"password\"></td>
  7. </tr>
  8. <tr>
  9. <td>New Pincode:</td>
  10. <td><input name=\"new\" type=\"password\"></td>
  11. </tr>
  12. <tr>
  13. <td></td>
  14. <td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
  15. </tr>
  16. </table>
  17. </form>

Our change pincode form.

PHP Code
  1. break;
  2.  
  3. case 'change':


Closes off our default page. Then makes the page ?page=change.

PHP Code
  1. $current = "$_POST[current]";
  2. $new = "$_POST[new]";
  3.  
  4. $sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
  5. $profile = mysql_fetch_array($sql);

Defines our variables. And grabs the members information from the database.

PHP Code
  1. if($current == NULL || $new == NULL)
  2. {
  3. die ("All fields are required.");
  4. }

Makes sure that the two fields aren't empty.

PHP Code
  1. if($current != $profile[pincode])
  2. {
  3. die ("Your current password does not match the posted password.");
  4. }

Makes sure that the posted current password is the same as in the database. (Security Reasons).

PHP Code
  1. else
  2. {
  3. $sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
  4. echo ("Pincode successfully changed.");
  5. }
  6. break;

Inserts the users new pincode. Gives a success message. and closes off the ?page=change section.

PHP Code
  1. }
  2. }
  3. else
  4. {
  5. echo ("Please login.");
  6. }
  7. ?>

Closes the ?page= function and closes off the logged in section. shows if the user is not logged in. And turns off the php coding.

Thats it for the tut.

be sure to look out for more by me.
SkillMaster's Avatar
Views:
2,581
Rating:
Posted on Thursday 27th March 2008 at 10:23 PM
ShadowMage
ShadowMage's Avatar
I've been told once or twice so no worries. ^^
Posted on Thursday 27th March 2008 at 09:27 PM
test
test's Avatar
i didnt know that was a requirement
Posted on Wednesday 26th March 2008 at 06:28 PM
ShadowMage
ShadowMage's Avatar
Next time could you use the contact tool to contact admins to add it to the script? :P
Posted on Wednesday 26th March 2008 at 03:37 AM
test
test's Avatar
This is a simple php file which enables the user to change there pin code from your website :) enjoy

<?php
session_start(); //allows session
include "config.php";
echo "<center>";
//checks see if there logged in
if($logged[id]) {
if(isset($_GET['update'])) {
$pincode = addslashes(htmlspecialchars($_POST[pincode]));
//updates there profile in the db
$update = mysql_query("UPDATE `members` SET `pincode` = '$pincode' WHERE `username` = '$logged[username]'");
echo "<font color='black'>Account Pincode Updated!</font>";
}else{
$getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$user = mysql_fetch_array($getuser);
echo "<font color='black'><p>Please keep this pincode in a safe as you will be required to use it in the event of your password being forgotten or lost</font></p><Br><form action='changepin.php?update' method='post'><table border='0'><tr>
<td align='left'><font color='black'>Account Pincode</font></td></tr><tr>
<td><input type='text' name='pincode' size='5' maxlength='5' value='$user[pincode]'></td></tr>
<tr>
<td colspan='2'><br><input type='submit' value='Update'></td></tr>
</table>
</form>";
}
}else{
echo "You are not logged in.";
}
echo "<center>";
?>
Posted on Friday 11th May 2007 at 09:54 PM
SkillMaster
SkillMaster's Avatar
Check your forum thing. also theres pretty much no point for the mail thing. if i understand you correctly
Posted on Friday 11th May 2007 at 08:46 PM
Diablosblizz
Diablosblizz's Avatar
Im trying to submit one with email reminder.. it took me about 20 minutes but then I ran into troubles and then I figured out that it was something so simple.
Posted on Friday 11th May 2007 at 08:45 PM
SkillMaster
SkillMaster's Avatar
You requested it. I made it. Took me literally 20 minutes to whip up. simple codes.
Posted on Friday 11th May 2007 at 08:26 PM
Diablosblizz
Diablosblizz's Avatar
Noo!! I was going to post it. Oh well - Mines dead anyways I can't get it to work.