#!/usr/bin/perl5 -w

my $password = "password"; 
print "password is $password\n\n"; 


my $encrypted_password = encrypt_passwd($password); 
print "encrypted password is $encrypted_password\n"; 


print "checking to see if $password equals password..\n\n"; 


my $checkit = (verify_passwd($encrypted_password,"password")); 
	if ($checkit eq "1") { 
    print "password passes!:\n"; 
	my $s=substr($encrypted_password,0,2);
	print(crypt("password",$s));
	print "\n\n"; 

}else{ 

	print "no, that's not it:\n"; 
	my $s=substr($encrypted_password,0,2);
	print(crypt("password",$s));
	print "\n\n"; 


} 



my $random_password = &generate_password; 
print "your daily randomly generated password: $random_password\n"; 


print "have fun everyone\n\n\n"; 

sub encrypt_passwd {
my $pw=shift;
# Seed random number generator. From Camel book p. 223.
srand ( time() ^ ($$ + ($$ << 15)) );                #best one


my @c=('a'..'z', 'A'..'Z', '0'..'9','.','/');
my $s=$c[rand(@c)].$c[rand(@c)];
return crypt($pw, $s);
}

sub verify_passwd {
my $check = 0; 
my ($epw, $pw)=@_;
my $s=substr($epw,0,2);
if($epw eq crypt($pw,$s)){ 
$check = 1; 
}


return $check; 

}



sub generate_password { 

     
my @chars = split '',
'abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789@#$%&*=+_<>?~';
     
    
        my $password;
      for(1..8){
      $password .= $chars[rand @chars];
         }
      return $password; 
      
 }