to change the password stored in file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

to change the password stored in file

Post by vb_123 »

Hi all,
i have a file called datafile.txt and the content of that file is.............
parag=parag
a=a
123456=123456
admin1=admin1
kapil=123456

in this file i am storing user name and password like in parag=parag first parag is user name and second parag is password.............
now i am writing a php code to change/update the password..................for that i have written code(its not completed) in "updatepass.php" ...............

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE> Update Password </TITLE></HEAD>

<BODY>
<form name="frm" method="post" action="updatepass.php">
<table width="450" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td>Enter Old Password : </td>
<td><input type="text" name="oldpwd" size="30"></td>
</tr>

<tr>
<td>Enter New Password : </td>
<td><input type="text" name="newpwd" size="30"></td>
</tr>

<tr>
<td>Confirm New Password : </td>
<td><input type="text" name="confpwd" size="30"></td>
</tr>

<tr>
<td><input type="submit" name="sub" value="Submit"></td>
</tr>

</table>
</form>
</body>
</html>

<?php

$oldPwd = $_POST['oldpwd'];
$newPwd= $_POST['newpwd'];
$confPwd= $_POST['confpwd'];

$file="datafile.txt";
$read=parse_ini_file($file);
foreach($read as $key=>$value)
{
if($value==$oldPwd)
{
if($newPwd==$confPwd)
{
$fp = fopen('datafile.ini', "w") or die ("cannot open file");
if(flock($fp, LOCK_EX))
{
$value=$newPwd;
.........................................
..........................................................................

}

}

}


?>

after $value=$newPwd; wat i need to do is to store the new password in "datafile.txt "
(to over the old content with a new content and rest file remain same)....so how can i do this............thanx in advance
User avatar
vargadanis
Forum Contributor
Posts: 158
Joined: Sun Jun 01, 2008 3:48 am
Contact:

Re: to change the password stored in file

Post by vargadanis »

Take a look at the fwrite or fputs functions at php.net. This website is you friend. :)
Post Reply