Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: String::MkPasswd still supported?

by karlgoethebier (Abbot)
on Sep 30, 2014 at 09:37 UTC ( [id://1102422]=note: print w/replies, xml ) Need Help??


in reply to String::MkPasswd still supported?

"... I needed a function to generate passwords so instead of writing my own..."

You may use the build-in features (/dev/random or /dev/urandom, Fisher-Yates by hand etc.) like described here: Re: Password (pseudo)casual.

Update:

"...instead of writing my own..

Don't mind: it's mine ;-)

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: String::MkPasswd still supported?
by Skeeve (Parson) on Nov 11, 2014 at 11:02 UTC
    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

      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://1102422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-03-28 09:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found