MD5 with salt in Perl and PHP

Hi all,
I'm trying to get a help desk application called otrs to use login details created by OSCommerce.

OSCommerce: PHP
OTRS: Perl


I've written a small PHP script which essentially does the same as OSCommerce.  This essentially works, giving me the result I want.
I have also tried to reproduce it in Perl, but not having much luck.

Output of PHP script (correct):
password=Passw0rd123
salt=1d
md5=c5a41df1ac002e57cf617961c274ccf4:1d

Output of Perl Script (wrong):
password=Passw0rd123
salt=1d
md5=$1$qYeqrN4B$rwLzj1eUA5dRfJjbU5ozu0:1d

How can I correct the perl script to be the same as PHP?  Am I using the right lib?


#PHP Script:
<?php
$str = 'Passw0rd123';
$salt = '1d';

$encr = md5($salt . $str);

echo "password=$str\n";
echo "salt=$salt\n";
echo "md5=$encr:$salt\n";

?>

-------------------------------------------------
#Perl Script:
#!/usr/bin/perl -wl
use strict;
use lib "/opt/otrs/Kernel/cpan-lib";
use Crypt::PasswdMD5 qw(unix_md5_crypt);

my $password='Passw0rd123';
my $salt='1d';
my $newstring = $salt . $password;

print "password=$password";
print "salt=$salt";
my $encrypted = unix_md5_crypt ($newstring);
print "md5=$encrypted:$salt";

Open in new window

LVL 4
amroxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sushiguruCommented:
I think (though I've not tested) that you want:

http://search.cpan.org/~gaas/Digest-MD5-2.39/MD5.pm

sg.
0
sushiguruCommented:
Forgot: md5_hex gives you a 32 char string using hex chars only.  Should be equivalent to PHP's md5.

sg.
use Digest::MD5 qw(md5 md5_hex);

my $password='Passw0rd123';
my $salt='1d';
my $newstring = $salt . $password;

print "password=$password";
print "salt=$salt";
my $encrypted = md5_hex ($newstring);
print "md5=$encrypted:$salt";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amroxAuthor Commented:
perfect, spot on, thank you
0
sushiguruCommented:
Glad to help, and thanks for the points :)

sg.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.