Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: String::MkPasswd still supported?

by Skeeve (Parson)
on Nov 11, 2014 at 11:02 UTC ( [id://1106804]=note: print w/replies, xml ) Need Help??


in reply to Re: String::MkPasswd still supported?
in thread String::MkPasswd still supported?

I took yours now:
#!/usr/bin/perl use strict; use warnings; print mkpasswd({ minlen => 8, maxlen => 10, lower => 1, special => 1, upper => 1, digit => 1, }); sub mkpasswd { my($param)= @_; if( not ref $param ) { $param= { minlen => $param, maxlen => $param, }; } if( ref $param eq 'HASH' ) { $param->{minlen}||= 8; $param->{maxlen}||= $param->{minlen} + 2; } my ( @l, @u, @n, @s, @p); open( URANDOM, "</dev/urandom" ) || die $!; read( URANDOM, $_, 4 ); close URANDOM; srand( unpack( "L", $_ ) ); @l = ( "a" .. "z" ); @u = ( "A" .. "Z" ); @n = ( 0 .. 9 ); @s = ( '#', ',', ' ', qw# ! " $ % & ' ( ) * + - . / : ; < = > ? @ [ \ ] ^ _ ` { | } + ~ # ); push( @p, $l[rand(@l)] ) for ( 1 .. $param->{lower} ); push( @p, $u[rand(@u)] ) for ( 1 .. $param->{upper} ); push( @p, $n[rand(@n)] ) for ( 1 .. $param->{digit} ); push( @p, $s[rand(@s)] ) for ( 1 .. $param->{special} ); my $m = $param->{minlen} - @p; $m=0 if $m<0; my $x = $param->{maxlen} - @p - $m + 1; $x=0 if $x<0; my(@j)= ( @l, @u, @s, @n ); $x= $m + rand($x); push( @p, $j[rand(@j)] ) for ( 1 .. $x ); for ( my $i = @p ; --$i ; ) { my $j = int( rand( $i + 1 ) ); next if $i == $j; @p[ $i, $j ] = @p[ $j, $i ]; } return join( "", @p ); }

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^3: String::MkPasswd still supported?
by karlgoethebier (Abbot) on Nov 11, 2014 at 12:38 UTC

    License granted without any warranty ;-)

    Regards, Karl

    P.S.: You may send some free beer for the monks to the cellerar's office.

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1106804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found