黑松山资源网 Design By www.paidiu.com
可以通过参数控制生成密码中包括的字符种类
#!/usr/bin/perl use strict; use warnings; use Getopt::Std; sub show_help { print "Useage:\n"; print "newp -aAnsl\n"; print "-a\t\t the password contains lower case letters(a-z)\n"; print "-A\t\t the password contains upper case letters(A-Z)\n"; print "-n\t\t the password contains numerical character(0-9)\n"; print "-s\t\t the password contains special symbols\n"; print "-u\t\t the password contains only unique characters\n"; print "-l length\t set the password length(default: 6)\n"; exit 0; } sub show_version { print "Version: 0.2.1 Changed the default option: -l 9 -Ana. 2016-4-15\n"; exit 0; } ### main program use vars qw($opt_a $opt_A $opt_h $opt_l $opt_n $opt_s $opt_u $opt_v); getopts('aAhl:nsuv'); &show_version if $opt_v; &show_help if $opt_h; my $len = $opt_l || 9; # default length 9 my $opt_cnt = 0; my @rand_str = (); # store all the characters my @num = qw(0 1 2 3 4 5 6 7 8 9); my @ABC = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z); my @abc = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z); # my @sym = qw(! " $ % & ' * + - . / : ; < = > " ' unshift (@sym, '(', ')', '#', ','); # to prevent perl's complains or warnings. my @all_sym = (@num, @ABC, @abc, @sym); my @ch_src = (); if ((!$opt_a) && (!$opt_A) && (!$opt_n) && (!$opt_s)) { $opt_a++; $opt_A++; $opt_n++; } if ($opt_a) { $opt_cnt++; my $i = rand @abc; unshift @rand_str, $abc[$i]; if ($opt_u) { if ($i>=1) { $abc[$i-1] = shift @abc; } else { shift @abc; } } unshift (@ch_src, @abc); } if ($opt_A) { $opt_cnt++; my $i = rand @ABC; unshift @rand_str, $ABC[$i]; if ($opt_u) { if ($i>=1) { $ABC[$i-1] = shift @ABC; } else { shift @ABC; } } unshift (@ch_src, @ABC); } if ($opt_n) { $opt_cnt++; my $i = rand @num; unshift @rand_str, $num[$i]; if ($opt_u) { if ($i>=1) { $num[$i-1] = shift @num; } else { shift @num; } } unshift (@ch_src, @num); } if ($opt_s) { $opt_cnt++; my $i = rand @sym; unshift @rand_str, $sym[$i]; if ($opt_u) { if ($i>=1) { $sym[$i-1] = shift @sym; } else { shift @sym; } } unshift (@ch_src, @sym); } if ($len < $opt_cnt) { print "The count of characters[$len] should not be smaller " . "than count of character types[$opt_cnt].\n"; exit -1; } if ($opt_u && $len > (@ch_src + @rand_str)) { print "The total number of characters[".(@ch_src + @rand_str). "] which could be contained " . "in password is smaller than the length[$len] of it.\n"; exit -1; } foreach (1..$len-$opt_cnt) { my $i = rand @ch_src; unshift @rand_str, $ch_src[$i]; if ($opt_u) { if ($i>=1) { $ch_src[$i-1] = shift @ch_src; } else { shift @ch_src; } } } foreach (1..$len) { my $i = rand @rand_str; print $rand_str[$i]; if ($i>=1) { $rand_str[$i-1] = shift @rand_str; } else { shift @rand_str; } } print "\n"; exit 0;
以上就是本文给大家分享的全部代码了,希望对大家学习Perl能够有所帮助
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年10月10日
2024年10月10日
- 炉石传说移动端商店打不开怎么办 移动端商店打不开解决方法分享
- 王菲《我的世界2》日本唱片志限量编号10CD[WAV+CUE]
- 乌兰托娅《爱从草原来HQII》头版限量编号[低速原抓WAV+CUE]
- 魏妙如.2017-《伟大的旅行》[WAV分轨]
- 科乐美送短跑冠军牌佬豪华礼包:顶罕卡片、决斗盘等
- 重大进展!PS4模拟器运行《重力眩晕:重制版》演示
- 南半球爱好者的福利 日本御姐级樱花妹高挑性感
- 玩家热议:哪些游戏通关后才算正式开始?
- 知名博主称赞《影之刃零》:有望成为现代最强之一?
- 泳衣快兜不住了!《莱莎工房》莱莎琳新手版开放预订
- 5.1版本「绘想游迹」全新游迹特效展示
- 原神纳塔篇OST&四周年分享H5正式上线
- 《原神》「星路拾忆」网页活动壁纸展示
- 群星.2024-祝你幸福!电影原声带【阿里巴巴】【FLAC分轨】
- 于台烟.2004-执着【乾坤唱片】【WAV+CUE】