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


In reply to Re: Would somebody like to comment this part of (PHP) code? by rruiz
in thread Would somebody like to comment this part of (PHP) code? by techcode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.