Can you interpret this snippet of Perl into PHP?

Associate
Joined
30 Dec 2005
Posts
415
As per title.

I'm trying to take some data from one database to a database used by PerlDesk. However, it uses encryption which I need a bit of help deciphering..

Code:
 ($salt) = $password =~ m/^(..)/; 
 
    require Digest::MD5; 
    my $md5 = Digest::MD5->new; 
    $md5->reset; 
 
    my $yday = (localtime)[7]; 
 
    my $certif = $user . $yday . "pd-$salt" . $ENV{'HTTP_USER_AGENT'} . $ENV{'REMOTE_ADDR'} 
      if $IP_IN_COOKIE; 
    $certif = $user . $yday . "pd-$salt" . $ENV{'HTTP_USER_AGENT'} if !$IP_IN_COOKIE; 
 
    $md5->add($certif); 
    my $enc_cert = $md5->hex

Can anyone explain to me / write the PHP code to take a raw password, and encrypt it using the above method?

Cheers
 
Completely untested, but it should work:

Code:
<?php

preg_match('#^(..)#', $password, $matches);
if ( !empty($matches) )
	$salt = $matches[1][0];

$yday = date('d');

if ( $IP_IN_COOKIE )
	$certif = $user . $yday . "pd-$salt" . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'];
else
	$certif = $user . $yday . "pd-$salt" . $_SERVER['HTTP_USER_AGENT'];

$enc_cert = md5($certif);

?>
 
robmiller said:
Completely untested, but it should work:

Code:
<?php

preg_match('#^(..)#', $password, $matches);
if ( !empty($matches) )
	$salt = $matches[1][0];

$yday = date('d');

if ( $IP_IN_COOKIE )
	$certif = $user . $yday . "pd-$salt" . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'];
else
	$certif = $user . $yday . "pd-$salt" . $_SERVER['HTTP_USER_AGENT'];

$enc_cert = md5($certif);

?>

Thanks very much :D

As always, Rob hits the nail on the head :)
 
Back
Top Bottom