分类:
2006-03-01 17:39:10
#!/usr/bin/perl use strict; use warnings; my $lowercase_chars = "abcdefghijklmnopqrstuvwxyz"; my $uppercase_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; my $numeric_chars = "1234567890"; my $other_chars = "`~!@#\$%^&*()-_=+[{}];:'\",./\\<>?|"; my $valid_chars = $lowercase_chars . $uppercase_chars; $valid_chars .= $numeric_chars . $other_chars; my $valid_chars_num = length($valid_chars); my $passwd; sub strchr { my $str = shift; my $ch = shift; foreach my $t (split('', $str)){ if($t eq $ch){ return 1; } } return 0; } while(1){ my $has = 0; $passwd = ""; for(my $i = 0; $i < 12; $i ++){ my $num = rand($valid_chars_num); $passwd .= substr($valid_chars, int($num) % length($valid_chars), 1); } foreach my $turn ($lowercase_chars, $uppercase_chars, $numeric_chars, $other_chars){ $has = 0; foreach my $ch (split('', $passwd)){ if(strchr($turn, $ch)){ $has = 1; last; } } if(!$has){ last; } } if($has){ print $passwd . "\n"; last; } } |