Code:
$userid = $_SESSION['username'];
$password2 = strtoupper(md5($newpass));
$initial=substr($userid,0,1);
// Looking for directory at account folder
if (ereg("^[a-zA-Z]$",$initial))
{
$initial=strtoupper($initial);
}
else
{
$initial="etc";
}
// Base directory for account
$accdir=("C:\kathana6\DBSRV\Account");
// Open and read file
$f=@fopen($accdir."\\".$initial."\\".$userid.".TAD",r) or die("Error");
$acc = @fread($f,7124);
// Close file
@fclose($f);
// Read password
$demopass=substr($acc,51,36); // start from 52th byte for 36 bytes
// Formatting password
$temppass = array (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); // Make sure it is 36 bytes
for(i=0; i<strlen($password2); i++)
{
$temppass[i] = ord($password2[i]); // not sure only ord or ordutf8
}
// Replace old password to new password
$acc = str_replace($demopass,$temppass,$acc);
// Open WRITE
$f2=@fopen($accdir."\\".$initial."\\".$userid.".TAD",w);
@fwrite($f2,$acc) or die("Error");
// Clean Up--
fclose($f2);