473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to use unix_md5_crypt from Perl in Python?

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:
>>username = 'root@localhost'
password = 'root'
import crypt
crypt.crypt(username, password)
'roowueH.vq6VM'
>>>
This creates 'roowueH.vq6VM' but not 'roK20XGbWEsSM'. :-(

Thanks in advance,
Nico
Mar 22 '07 #1
1 3542
Nico Grubert <ni*********@gmail.comwrites:
Example:
username = 'root@localhost'
password = 'root'

The crypted password is: 'roK20XGbWEsSM'
that looks like you want crypt(3), not md5. See:

http://docs.python.org/lib/module-crypt.html

Sample session:
>>import crypt
print crypt.crypt('root','ro')
roK20XGbWEsSM
>>>
Mar 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Roy Smith | last post by:
I'm working on a prototype of a new application in Python. At some point, if this ever turns into a product, the powers that be will almost certainly demand that it be done in Perl. My job will...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
46
by: Reinhold Birkenfeld | last post by:
Hello, another Perl/Python question: the subject says it all. Perl is going to change dramatically to become a more powerful and easier to (read|write) language. Is Python taking a similar...
17
by: Michael McGarry | last post by:
Hi, I am just starting to use Python. Does Python have all the regular expression features of Perl? Is Python missing any features available in Perl? Thanks, Michael
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
9
by: Dieter Vanderelst | last post by:
Dear all, I'm currently comparing Python versus Perl to use in a project that involved a lot of text processing. I'm trying to determine what the most efficient language would be for our...
13
by: squash | last post by:
I am a little annoyed at why such a simple program in Perl is causing so much difficulty for python, i.e: $a += 200000 * 140000; print $a;
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
8
by: Palindrom | last post by:
Hi everyone ! I'd like to apologize in advance for my bad english, it's not my mother tongue... My girlfriend (who is a newbie in Python, but knows Perl quite well) asked me this morning why...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.