Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Would somebody like to comment this part of (PHP) code?

by rruiz (Monk)
on Aug 21, 2005 at 09:07 UTC ( #485507=note: print w/ replies, xml ) Need Help??


in reply to Would somebody like to comment this part of (PHP) code?

You almost got it all figured. I think that what you need is to find a way to generate the same MD5 hash in Perl, as the PHP md5() function. And you can do it with the md5_hex() function of the Digest::MD5 module. A simple search on google for "md5 compare Digest::MD5 php perl", will find the PHP Documentation for the md5() function. There is an example of how to do it.

And while you are at google, search also for "oscommerce php home", go to the home page of the osCommerce project, download the source and unpack them so you can easyly find the tep_* functions with winblows exploder find (it seems like a convention on library functions in the osCommerce source, but I don't know if that's it or not). Also you should find more documentation about osCommerce there that may help you in understanding how to interface with it from Perl (or you may not, I have not tried it).

As for the specifics in the code you mention, the tep_validate_password() function is spliting the $encrypted word in the array $stack, to retrieve the salt to encrypt the $plain password passed to it (something easy to overlook because there is no @ in PHP and you are thinking in Perl). So, something like:

use Digest::MD5 qw(md5_hex); sub tep_perl_validate_password { my ($plain, $encrypted) = @_; return 0 unless defined($plain) && defined($encrypted); my @stack = split ':', $encrypted; return 0 if(scalar(@stack) != 2); return md5_hex( $stack[1] . $plain ) eq $stack[0]; }

Should do the same as the PHP function mentioned. (NOTE: All code is untested)

And for help on what the PHP standard functions do (like explode(), size_of(), and others without tep_), you may consult the PHP site, or some of the many forums out there that deal with that language. Then come back here with more specific Perl questions, ;)

Update: (1) Replaced $encrypted with $stack[0] on last line of sub. (2) Another typo in defined($encrypted).

HTH, God bless you
rruiz


Comment on Re: Would somebody like to comment this part of (PHP) code?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://485507]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2014-08-30 06:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls