From 1cb97260ba73480d5aabbc9d3929935d1b272a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 28 Jul 2012 20:32:24 +0200 Subject: [PATCH] Password generator --- README | 1 + README.OtherScripts | 9 +++++++++ make-password.pl | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 README.OtherScripts create mode 100755 make-password.pl diff --git a/README b/README index 5e84348..f7af41e 100644 --- a/README +++ b/README @@ -3,4 +3,5 @@ This repo contains various scripts which I figure could be useful to someone. backup/ A set of backup scripts ban-ssh-morons/ A "SSH bruteforce attempts to iptables blacklist" daemon +See README.OtherScripts for scripts too small to deserve their own directory. License: WTFPL (http://sam.zoy.org/wtfpl/) diff --git a/README.OtherScripts b/README.OtherScripts new file mode 100644 index 0000000..1c7f46a --- /dev/null +++ b/README.OtherScripts @@ -0,0 +1,9 @@ +make-password.pl +----------------- + +Generates a random password. Usage: + + perl make-password.pl [simple] [] + +"simple" indicates that the password should consist of alphanumeric characters +only. If no length is specified, the default is 13. diff --git a/make-password.pl b/make-password.pl new file mode 100755 index 0000000..29e11c6 --- /dev/null +++ b/make-password.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use strict; + +sub genPassword +{ + my $len = shift; + my $simple = shift; + my @characters; + @characters = ( 'A' .. 'Z' , 'a' .. 'z' , '0' .. '9' ); + unless ( $simple ) { + @characters = ( @characters , + '!' , '=' , '+' , '-' , '/' , '*' , '.' , + '(' , ')' , '[' , ']' , '{' , '}' ); + } + while ( @characters < $len * 2 ) { + @characters = ( @characters , @characters ); + } + for ( my $i = 0 ; $i < 10 ; $i ++ ) { + @characters = sort { int( rand() * 3 ) - 1 } @characters; + } + return join( '' , @characters[ 0 .. ( $len - 1 ) ] ); +} + +my $mlen = 13; +my $simple = 0; +if ( $ARGV[0] eq 'simple' ) { + shift @ARGV; + $simple = 1; +} +$mlen = int( $ARGV[0] ) if $ARGV[0]; +print genPassword( $mlen , $simple ) . "\n";