From ebadc8100a58cfdd4edb31d9a873dfc05b181df8 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 9 Feb 2013 18:03:36 -0800 Subject: [PATCH] Move dictionary func into a common library --- useradmin/md5-lib.pl | 34 ++++++++++++++++++++++++++++++++++ useradmin/user-lib.pl | 34 ---------------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/useradmin/md5-lib.pl b/useradmin/md5-lib.pl index 61ae44ad3..7084c5c0b 100755 --- a/useradmin/md5-lib.pl +++ b/useradmin/md5-lib.pl @@ -249,5 +249,39 @@ return 1 if ($ohash eq $hash); return 0; } +=head2 is_dictionary_word(word) + +Returns 1 if some file can be found in a dictionary words file + +=cut +sub is_dictionary_word +{ +my ($word) = @_; +$word = lc($word); +my @files; +if ($config{'dict_file'}) { + @files = split(/\s+/, $config{'dict_file'}); + } +else { + @files = ( "/usr/share/dict/words", + "/usr/dict/words" ); + } +foreach my $f (@files) { + my $found = 0; + &open_readfile(WORDS, $f); + while() { + s/#.*//; + s/\s//; + if (lc($_) eq $word) { + $found = 1; + last; + } + } + close(WORDS); + return 1 if ($found); + } +return 0; +} + 1; diff --git a/useradmin/user-lib.pl b/useradmin/user-lib.pl index 5c29b817c..34e11af0d 100755 --- a/useradmin/user-lib.pl +++ b/useradmin/user-lib.pl @@ -1593,40 +1593,6 @@ if ($config{'passwd_mindays'} && $uinfo ne "none") { return undef; } -=head2 is_dictionary_word(word) - -Returns 1 if some file can be found in a dictionary words file - -=cut -sub is_dictionary_word -{ -my ($word) = @_; -$word = lc($word); -my @files; -if ($config{'dict_file'}) { - @files = split(/\s+/, $config{'dict_file'}); - } -else { - @files = ( "/usr/share/dict/words", - "/usr/dict/words" ); - } -foreach my $f (@files) { - my $found = 0; - &open_readfile(WORDS, $f); - while() { - s/#.*//; - s/\s//; - if (lc($_) eq $word) { - $found = 1; - last; - } - } - close(WORDS); - return 1 if ($found); - } -return 0; -} - =head2 check_username_restrictions(username) Returns an error message if a username fails some restriction, or undef if