[interchange: 1/2] * Use Vend::Util::SHA1 in UserDB.

Mike Heins <[email protected]>
Newsgroups gmane.comp.web.interchange.cvs
Message-ID <[email protected]>
commit a9b14c27a1f8e07d2cc1cef2c975dcbaae0c37da
Author: Mike Heins <[email protected]>
Date:   Fri Jul 12 09:20:46 2013 -0400

    * Use Vend::Util::SHA1 in UserDB.
    * Fail hard if UserDB uses SHA1 encryption sub but no module.
    * Clean up code in Util.pm to separate blocks entirely.

 lib/Vend/Config.pm |   10 +++++++---
 lib/Vend/UserDB.pm |    4 ++--
 lib/Vend/Util.pm   |   14 +++++++-------
 3 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/lib/Vend/Config.pm b/lib/Vend/Config.pm
index 59eb770..72eae5f 100644
--- a/lib/Vend/Config.pm
+++ b/lib/Vend/Config.pm
@@ -3481,9 +3481,13 @@ sub set_default_search {
 		UserDB => sub {
 					my $set = $C->{UserDB_repository};
 					for(keys %$set) {
-						next unless defined $set->{$_}{admin};
-						$C->{AdminUserDB} = {} unless $C->{AdminUserDB};
-						$C->{AdminUserDB}{$_} = $set->{$_}{admin};
+						if( defined $set->{$_}{admin} ) {
+							$C->{AdminUserDB} = {} unless $C->{AdminUserDB};
+							$C->{AdminUserDB}{$_} = $set->{$_}{admin};
+						}
+						if($set->{$_}{encsub} =~ /sha1/i and ! $Vend::Util::SHA1) {
+							return(undef, "Unable to use SHA1 encryption for UserDB, no Digest::SHA or Digest::SHA1 module.");
+						}
 					}
 					return 1;
 				},
diff --git a/lib/Vend/UserDB.pm b/lib/Vend/UserDB.pm
index ffcfbd3..ee43f08 100644
--- a/lib/Vend/UserDB.pm
+++ b/lib/Vend/UserDB.pm
@@ -100,11 +100,11 @@ sub enc_md5_salted {
 
 sub enc_sha1 {
     my $obj = shift;
-    unless ($HAVE_SHA) {
+    unless ($Vend::Util::SHA1) {
         $obj->log_either('SHA passwords unavailable. Is Digest::SHA installed?');
         return;
     }
-    return Digest::SHA::sha1_hex(shift);
+    return Vend::Util::sha1_hex(shift);
 }
 
 # Maps the length of the encrypted data to the algorithm that
diff --git a/lib/Vend/Util.pm b/lib/Vend/Util.pm
index a69aeb4..a8a2683 100644
--- a/lib/Vend/Util.pm
+++ b/lib/Vend/Util.pm
@@ -571,15 +571,9 @@ sub random_string {
     $r;
 }
 
-# To generate a unique key for caching
-# Not very good without MD5
-#
-my $Md;
-my $Keysub;
-
+##  This block defines &Vend::Util::sha1_hex and $Vend::Util::SHA1
 use vars qw($SHA1);
 
-##  This block defines &Vend::Util::sha1_hex and $Vend::Util::SHA1
 BEGIN {
 
 	$SHA1 = 1;
@@ -599,6 +593,12 @@ BEGIN {
 	  }
 }
 
+# To generate a unique key for caching
+# Not very good without MD5
+#
+my $Md;
+my $Keysub;
+
 eval {require Digest::MD5 };
 
 if(! $@) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.