How to use unix_md5_crypt from Perl in Python?

N

Nico Grubert

Dear list members,

I have a Perl script which crypts a password using a clearteaxt password
and a username.

Example:
username = 'root@localhost'
password = 'root'

The crypted password is: 'roK20XGbWEsSM'

The crypted password always starts with the first 2 characters of the
username (here: 'ro' from 'root@localhost').

The Perl script contains this code and I am wondering how I can do this
in Python:
#################################################################################
my $CryptedPw = '';
# md5 pw
if ($Self->{ConfigObject}->Get('AuthModule::DB::CryptType') &&
$Self->{ConfigObject}->Get('AuthModule::DB::CryptType') eq 'md5') {
$CryptedPw = unix_md5_crypt($Pw, $Param{UserLogin});
}
# crypt pw
else {
# crypt given pw (unfortunately there is a mod_perl2 bug
# on RH8 - check if
# crypt() is working correctly) :-/
if (crypt('root', 'root@localhost') eq 'roK20XGbWEsSM') {
$CryptedPw = crypt($Pw, $Param{UserLogin});
}
else {
$Self->{LogObject}->Log(
Priority => 'notice',
Message => "The crypt() of your mod_perl(2) is not working
correctly! Update mod_perl!",
);
my $TempUser = quotemeta($Param{UserLogin});
my $TempPw = quotemeta($Pw);
my $CMD = "perl -e \"print crypt('$TempPw', '$TempUser');\"";
open (IO, " $CMD | ") || print STDERR "Can't open $CMD: $!";
while (<IO>) {
$CryptedPw .= $_;
}
close (IO);
chomp $CryptedPw;
}
}
#################################################################################


What do I have to do in Python to create the crypted password
'roK20XGbWEsSM' by using 'root@localhost' for username and 'root' for
password?

I tried:
This creates 'roowueH.vq6VM' but not 'roK20XGbWEsSM'. :-(

Thanks in advance,
Nico
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top