Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created March 1, 2013 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/5063412 to your computer and use it in GitHub Desktop.
Save mamemomonga/5063412 to your computer and use it in GitHub Desktop.
ランダムなパスワードを30個作る。間違えやすい文字を除外して作る。
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Math::Random::MT;
sub random_password {
my $len=shift || 10;
my $gen=Math::Random::MT->new();
my $chars1='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
#my $chars2='#~!@$%^&*()_+=-{}|:"<>?/.\';][\\';
my $chars2='&*()_-?';
my $chars=$chars1.$chars1.$chars2;
my @chars;
for(my $i=0;$i<length($chars);$i++) {
push @chars,substr($chars,$i,1);
}
my $chars_len=$#chars;
my @buf;
foreach(1..$len) {
push @buf,$chars[int($gen->rand($chars_len+1))];
}
return join('',@buf);
}
foreach(1..30) {
print random_password($ARGV[0])."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment