Move API to check password hash to md5-lib.pl
authorJamie Cameron <jcameron@webmin.com>
Fri, 8 Apr 2011 23:13:03 +0000 (16:13 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 8 Apr 2011 23:13:03 +0000 (16:13 -0700)
useradmin/md5-lib.pl
useradmin/user-lib.pl

index faba73e..58e0319 100755 (executable)
@@ -210,5 +210,44 @@ $salt ||= '$6$'.substr(time(), -8).'$';
 return crypt($passwd, $salt);
 }
 
+# validate_password(password, hash)
+# Compares a password with a hash to see if they match, returns 1 if so,
+# 0 otherwise. Tries all supported hashing schemes.
+sub validate_password
+{
+local ($passwd, $hash) = @_;
+
+# Classic Unix crypt
+local $chash = eval {
+       local $main::error_must_die = 1;
+       &unix_crypt($passwd, $hash);
+       };
+return 1 if ($chash eq $hash);
+
+# MD5
+if (!&check_md5()) {
+       local $mhash = &encrypt_md5($passwd, $hash);
+       return 1 if ($mhash eq $hash);
+       }
+
+# Blowfish
+if (!&check_blowfish()) {
+       local $mhash = &encrypt_blowfish($passwd, $hash);
+       return 1 if ($mhash eq $hash);
+       }
+
+# SHA1
+if (!&check_sha512()) {
+       local $shash = &encrypt_sha512($passwd, $hash);
+       return 1 if ($shash eq $hash);
+       }
+
+# Some other hashing, maybe supported by crypt
+local $ohash = eval { crypt($passwd, $hash) };
+return 1 if ($ohash eq $hash);
+
+return 0;
+}
+
 1;
 
index bab7bae..8f231bf 100755 (executable)
@@ -1821,45 +1821,6 @@ else {
        }
 }
 
-# validate_password(password, hash)
-# Compares a password with a hash to see if they match, returns 1 if so,
-# 0 otherwise. Tries all supported hashing schemes.
-sub validate_password
-{
-local ($passwd, $hash) = @_;
-
-# Classic Unix crypt
-local $chash = eval {
-       local $main::error_must_die = 1;
-       &unix_crypt($passwd, $hash);
-       };
-return 1 if ($chash eq $hash);
-
-# MD5
-if (!&check_md5()) {
-       local $mhash = &encrypt_md5($passwd, $hash);
-       return 1 if ($mhash eq $hash);
-       }
-
-# Blowfish
-if (!&check_blowfish()) {
-       local $mhash = &encrypt_blowfish($passwd, $hash);
-       return 1 if ($mhash eq $hash);
-       }
-
-# SHA1
-if (!&check_sha512()) {
-       local $shash = &encrypt_sha512($passwd, $hash);
-       return 1 if ($shash eq $hash);
-       }
-
-# Some other hashing, maybe supported by crypt
-local $ohash = eval { crypt($passwd, $hash) };
-return 1 if ($ohash eq $hash);
-
-return 0;
-}
-
 =head2 build_user_used([&uid-hash], [&shell-list], [&username-hash])
 
 Fills in hashes with used UIDs, shells and usernames, based on existing users.