(php) MD5SUMming. need some help

Custom Title Activated
Loyal Member
Joined
Nov 28, 2004
Messages
2,236
Reaction score
0
Need help from advanced php coders.

Situation: I got 1 PHP script and 1 BAT script.

The script.php contains:
PHP:
<?php
$str = ($_REQUEST['sid']);
$pwd = date(d).date(H)."tomas"."\n";
$secret = md5($pwd);

if ($str === $secret ) {
// I'll know what to do when everyting is OK
   echo "MD5SUM is OK!\nMD5SUM is: ".$secret;
   exit;
**
else {
// Will add 'die', I guess...
   echo "wrong md5. md5sum is:".$secret."<BR>";
   echo "DEBUG: "."PARAM: ".$str." PWD: ".$pwd." SECERT PWD MD5SUM: ".$secret."<BR>";
**
?>
script.bat contents:
Code:
set currentday= 00
rem (i'll generate the current day. dont remember syntax. doesnt matter. this gives 2 digit code)
set currenthour= 00
rem (i'll generate the current hour. dont remember syntax. doesnt matter. this gives 2 digit code)
echo %currentday%%currenthour%tomas>output.txt
md5sum output.txt> the_code.txt

rem then I extract the the_code.txt and get 32 MD5SUM code and give it to the php script. don't go into details how

so here what my script do, or it should do...

I execute script.php. It gets the current day and hour values, some text and generates such var, i.e.:
2210tomas
the problem is that dos outputs the var into file not like this:
Code:
2210tomas
but like this
Code:
2210tomas
(one empty line)
not goint into details I will tell that I wouln't fix this, so do not bother to tell me how to do smth bout this.

ok, so we continue.
then I use md5sum.exe and generate MD5 of
Code:
2210tomas
(one empty line)
then I extract the MD5SUM from the file and submit the script:
Code:
http://..//..//script.php?sid=<the md5 sum>
but here's where the problem comes. if I generate MD5SUM (in BAT part) of the single line with no [enter]s I get the correct code and the PHP script works. I tried to add "\n" in the php to act as the line break, but the MD5SUM of my TXT file and the one in PHP script don't match. moreover, if I try to make the complex string to be calculated with md5 command, the sums does not match (I mean when I link variables/text with ".").

So how sould I fix the PHP so the sums would match? I was thinking on making the txt file in WWW server within php script so then the structures would meet (since I can't get rid of line break in DOS)

I think I made it very complex to understand what I want :).
Please ask if it isn't clear what I want..
 
Have you tried using chr(13).chr(10) instead of "\n"? Cuz on Windows \n is made up of those 2 chars, though I'm not sure if PHP outputs it as 13 10 or just 13, so you might wanna check that out :)
 
the line break means you generate your md5 on a totally different string, resulting in a totally different md5.
so yes it's probably best to generate that txt file in your script if you cant get rid of that linebreak

(im not experienced at md5 but that's what i make of it)
 
Back