#!/usr/bin/perl -w # # Copyright (C) 2005 Tom Geissler # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # # version 0.1 # 30.10.2005 use strict; use locale; # perl -MCPAN -e shell # cpan> install Crypt::Cracklib use Crypt::Cracklib; # min. number of upper, lower, digit and punct characters my $mincount = 1; # min. password length my $minlength = 7; my $c_upper = my $c_lower = my $c_digit = my $c_punct = 0; # path to the password dictionary my $cracklib_dict = "/var/cache/cracklib/cracklib_dict"; my $passwd = ; chop($passwd); if ($passwd eq '') { print("ERROR - Failed to read password\n"); exit(-1); } if (length($passwd) < $minlength) { print("ERROR - Password to short\n"); exit(-2); } if ($passwd =~ /[^[:graph:]+]/) { print("ERROR - Password contains bad characters\n"); exit(-3); } if ($passwd =~ /[[:upper:]]{$mincount,}/) {$c_upper = 1;} if ($passwd =~ /[[:lower:]]{$mincount,}/) {$c_lower = 1;} if ($passwd =~ /[[:digit:]]{$mincount,}/) {$c_digit = 1;} if ($passwd =~ /[[:punct:]]{$mincount,}/) {$c_punct = 1;} if (($c_upper + $c_lower + $c_digit + $c_punct) < 3 ) { print( "ERROR - Password way to simple\n"); exit(-4); } if (!check($passwd, $cracklib_dict)) { print( "ERROR - Password is based on an dictionary word\n"); exit(-5); } exit(0);