--- helpers/basic_auth/DB/squid_db_auth.in	2010-05-01 13:39:52.000000000 +0200
+++ helpers/basic_auth/DB/squid_db_auth.in.dlucio	2010-05-01 17:10:02.000000000 +0200
@@ -1,8 +1,9 @@
 #!@PERL@
-use strict;
+#use strict;
 use DBI;
 use Getopt::Long;
 use Pod::Usage;
+use Digest::MD5 qw(md5 md5_hex md5_base64);
 $|=1;
 
 =pod
@@ -22,6 +23,8 @@
 my $db_cond = "enabled = 1";
 my $plaintext = 0;
 my $persist = 0;
+my $isjoomla = 0;
+my $debug = 0;
 
 =pod
 
@@ -62,6 +65,7 @@
 =item	B<--cond>
 
 Condition, defaults to enabled=1. Specify 1 or "" for no condition
+If you use --joomla flag, this condition will be changed to block=0
 
 =item	B<--plaintext>
 
@@ -71,6 +75,10 @@
 
 Keep a persistent database connection open between queries. 
 
+=item  B<--joomla>
+
+Tell helper that user database is joomla db.  So salt hasing is understood.
+
 =back
 
 =cut
@@ -85,9 +93,12 @@
 	'cond=s' => \$db_cond,
 	'plaintext' => \$plaintext,
 	'persist' => \$persist,
+	'joomla' => \$isjoomla,
+	'debug' => \$debug,
 	);
 
 my ($_dbh, $_sth);
+$db_cond = "block = 0" if $isjoomla;
 
 sub close_db()
 {
@@ -113,9 +124,17 @@
 {
     my ($password, $key) = @_;
 
-    return 1 if crypt($password, $key) eq $key;
-    
-    return 1 if $plaintext && $password eq $key;
+    if ($isjoomla){
+        my $salt;
+        my $key2;
+        ($key2,$salt) = split (/:/, $key);
+        return 1 if md5_hex($password.$salt).':'.$salt eq $key;
+    }
+    else{
+        return 1 if crypt($password, $key) eq $key;
+     
+        return 1 if $plaintext && $password eq $key;
+    }
 
     return 0;
 }
@@ -155,6 +174,7 @@
 =head1 COPYRIGHT
 
 Copyright (C) 2007 Henrik Nordstrom <henrik@henriknordstrom.net>
+Copyright (C) 2010 Luis Daniel Lucio Quiroz <dlucio@okay.com.mx> (Joomla support)
 This program is free software. You may redistribute copies of it under the
 terms of the GNU General Public License version 2, or (at youropinion) any
 later version.

