Forgot Password / Register
Site Statistics
Total Members: 509
Total Tutorials: 242
Newsest User: Lestop
Todays Unique Hits: 160
0 Users 5 Guests Online

Change Pincode

Change Pincode:

by request,
save this as chpin.php
Code

<?php
include("config.php");
if($logged[username])
{
switch($_GET[page])
{
default:
echo ("
<strong>Change Pincode:</strong>
<form method=\"post\" action=\"?page=change\">
<table>
<tr>
<td>Current Pincode:</td>
<td><input name=\"current\" type=\"password\"></td>
</tr>
<tr>
<td>New Pincode:</td>
<td><input name=\"new\" type=\"password\"></td>
</tr>
<tr>
<td></td>
<td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
</tr>
</table>
</form>
");
break;

case 'change':
$current = "$_POST[current]";
$new = "$_POST[new]";

$sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$profile = mysql_fetch_array($sql);

if($current == NULL || $new == NULL)
{
die ("All fields are required.");
}
if($current != $profile[pincode])
{
die ("Your current password does not match the posted password.");
}
else
{
$sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
echo ("Pincode successfully changed.");
}
break;
}
}
else
{
echo ("Please login.");
}
?>

Define:
Code

<?php
include("config.php");
if($logged[username])
{
switch($_GET[page])
{

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

Code

<strong>Change Pincode:</strong>
<form method=\"post\" action=\"?page=change\">
<table>
<tr>
<td>Current Pincode:</td>
<td><input name=\"current\" type=\"password\"></td>
</tr>
<tr>
<td>New Pincode:</td>
<td><input name=\"new\" type=\"password\"></td>
</tr>
<tr>
<td></td>
<td><input name=\"Submit\" type=\"Submit\" value=\"Change Pincode\"></td>
</tr>
</table>
</form>

Our change pincode form.

Code

break;

case 'change':


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

Code

$current = "$_POST[current]";
$new = "$_POST[new]";

$sql = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'");
$profile = mysql_fetch_array($sql);

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

Code

if($current == NULL || $new == NULL)
{
die ("All fields are required.");
}

Makes sure that the two fields aren't empty.

Code

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

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

Code

else
{
$sql = mysql_query("UPDATE `members` SET `pincode` = '$new' WHERE `username` = '$logged[username]'");
echo ("Pincode successfully changed.");
}
break;

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

Code

}
}
else
{
echo ("Please login.");
}
?>

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
Views:
1649
Rating:
Posted on Thursday 27th March 2008 at 10:23 PM
ShadowMage
ShadowMage
I've been told once or twice so no worries. ^^
Posted on Thursday 27th March 2008 at 09:27 PM
test
test
i didnt know that was a requirement
Posted on Wednesday 26th March 2008 at 06:28 PM
ShadowMage
ShadowMage
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
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
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
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
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
Noo!! I was going to post it. Oh well - Mines dead anyways I can't get it to work.