#! /usr/bin/perl -w

##### Program description #######
#
# Title:     cgi5.pl
# Author(s): Mattias Ohlsson
# Description:
#   Small example of how to use the CGI module.
#
##################################

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $cgi = new CGI;

print $cgi->header,
    $cgi->start_html(-title=>'Password validation form'),
    $cgi->h1('A small utility to validate passwords');

if ( $cgi->param() ) {

   # Get the password
   my $passwd = $cgi->param("passwd");

   if ($passwd =~ /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[%\.@#\$]).{8,}$/) {
      print $cgi->p, "PASS: Your password is safe!";
   } else {
      print $cgi->p, "WARNING: Your password is unsafe!";
   }

} else {

    print $cgi->start_form,
    $cgi->p, "Type password here ", $cgi->password_field("passwd"),
    $cgi->p, $cgi->submit("Validate"), $cgi->reset("Clear"),
    $cgi->end_form();

}
print $cgi->end_html();
