Gossamer Forum
Quote Reply
MD5() via GT::SQL
Hi,

I'm trying to encrypt a password using the same method as WordPress (MD5()).

The PHP code used to encrypt the passwords, is;

$wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'");

From the looks of things, thats usings PHP's built in MD5() function. However, I obviously can't use that in a Perl script.

Having a look at the help page on php.net (http://uk.php.net/...nction.md5.php#31238)

Quote:
From the documentation on Digest::MD5:
md5($data,...)
This function will concatenate all arguments, calculate the MD5 digest of this "message", and return it in binary form.

md5_hex($data,...)
Same as md5(), but will return the digest in hexadecimal form.

PHP's function returns the digest in hexadecimal form, so my guess is that you're using md5() instead of md5_hex(). I have verified that md5_hex() generates the same string as PHP's md5() function.

(original comment snipped in various places)
>Hexidecimal hashes generated with Perl's Digest::MD5 module WILL
>NOT equal hashes generated with php's md5() function if the input
>text contains any non-alphanumeric characters.
>
>$phphash = md5('pa$$');
>echo "php original hash from text: $phphash";
>echo "md5 hash from perl: " . $myrow['password'];
>
>outputs:
>
>php original hash from text: 0aed5d740d7fab4201e885019a36eace
>hash from perl: c18c9c57cb3658a50de06491a70b75cd

So in short.. how on earth can I create the same kind of MD5 string in Perl?

Basically, I need to encrypt it in Perl.. and put it in the same table as WordPress uses (which is using the MD5) encryption method). Really got my mind boggled Unimpressed

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] MD5() via GT::SQL In reply to
Seems that we have some missunderstanding here Wink

In the providded example from WordPress it uses internal MySQL MD5 crypt metod not php!

Here the 2 tests!

1. I've used the MySQL encriptin in style of WordPress
UPDATE login_comm_users SET comm_password = MD5('password') WHERE comm_username = 'testing';
produces for password: 914b8a6435929b78481cfc2f0e33edf6

2. Now we try with Digest::MD5
#!/usr/bin/perl

use Digest::MD5 'md5_hex';

print 'Digest is ', md5('AiROMj0k'), "\n";

which produces: 914b8a6435929b78481cfc2f0e33edf6

and in closer look:
Code:
MySQL: 914b8a6435929b78481cfc2f0e33edf6
Perl: 914b8a6435929b78481cfc2f0e33edf6


Where is the diff? Tongue

Hope this helps

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins

Last edited by:

eupos: Nov 25, 2005, 3:50 AM
Quote Reply
Re: [Andy] MD5() via GT::SQL In reply to
Andy, there is a GT::MD5 module in Links, the Auth_vBulletin plugin uses it quite a bit.
Quote Reply
Re: [aus_dave] MD5() via GT::SQL In reply to
Hi,

Managed to get it working with the MySQL MD5() function :)

$DB->table('Table')->update( { Field => \"MD5('$hit->{NEWPASSWORD}')" } ) || die $GT::SQL::error;

Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] MD5() via GT::SQL In reply to
Hi,

Just FYI :)

I've tested this with GT::MD5 and does job as well :)

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [Andy] MD5() via GT::SQL In reply to
Quote:
From the looks of things, thats usings PHP's built in MD5() function.

That would have been md5 not MD5.
Quote Reply
Re: [Hargreaves] MD5() via GT::SQL In reply to
In Reply To:
Quote:
From the looks of things, thats usings PHP's built in MD5() function.

That would have been md5 not MD5.
Ya. Can you tell I havn't used PHP for a good 8 months? Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!