[Rt-devel] Converting md5 base64 to md5 hex
Winn Johnston
winn_johnston at yahoo.com
Wed Apr 19 13:47:07 EDT 2006
Thanks to Ruslan and his piece of code i was able to right this script. It will be helpfull to anyone upgrading to RT 3.4.5 , and people who use to rt database to authentacate users for other pieces of software. It seems RT 3.4.5 uses an MD5 HEX encoding system, but for backwards compatability it can read MD5 base64 encoded passwords. However as users log into the new system the passwords are re-encoded and stored in the new HEX format. This script will change all the passwords to HEX and leave any blank passwords alone. Hope this helps :)
#!/usr/bin/perl
# load module
use DBI;
use MIME::Base64 qw();
use bytes;
#query
my $query = qq(
SELECT *
From Users
WHERE CHAR_LENGTH(Password)< 32 AND (CHAR_LENGTH(Password) != 0) AND (CHAR_LENGTH(Password) != 13)
);
# connect
my $dbh = DBI->connect("DBI:mysql:database=rt3;host=localhost", "root", "", {'RaiseError' => 1});
my $sth = $dbh->prepare($query);
$sth->execute();
# iterate through resultset
# print values
while(my $ref = $sth->fetchrow_hashref()) {
$old_encoded_pwd = $ref->{'Password'};
my $md5 = MIME::Base64::decode($old_encoded_pwd);
$md5 =~ s/(.)/sprintf "%02x",ord($1)/gmse;
print "User: $ref->{'Name'}\n";
print "Password: $ref->{'Password'}\n";
print "New Password: '$md5'\n";
# execute INSERT query
my $rows = $dbh->do("update Users SET Password= '$md5' WHERE Name='$ref->{Name}';");
print "$rows row(s) affected\n";
print "----------\n";
}
# clean up
$dbh->disconnect();
---------------------------------
Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bestpractical.com/pipermail/rt-devel/attachments/20060419/faad45e3/attachment.htm
More information about the Rt-devel
mailing list