When I need to set an initial password for someone at the office, I turn to this simple program:

use strict; use warnings; my @alphabet = ( '0' .. '9', 'a' .. 'z', 'A' .. 'Z' ); my $length = shift @ARGV || 8; my $out = ''; while ( length $out < $length ) { $out .= $alphabet[ rand @alphabet ]; } print "$out\n";

A coworker remarked recently, "you're really not trying to make this easy, are you." Well, no.

This evening I thought about golfing this down to a one liner to make it easier to paste into a chat, and this is what I came up with:

perl -E '@a=("0".."9","A".."Z","a".."z");$o.=$a[rand@a]while 8>length$ +o;say$o'

I don't doubt that this could be improved greatly. Any monk who wants to play along should try to generate passwords of 8–15 characters from an alphabet that includes letters and non-letters (/\w/ and /\W/). The more secure the results, the better.

I'd consider a side discussion of manual password selection methods also to be on topic. My personal favorite is to take the initials of some phrase that I can recall reliably, usually a quote from a movie or a song lyric ("happy birthday to you" would be "hb2U"). At a company I used to work for, we'd set root on all the machines using different parts of a single song. If I was caught without my password list, I could go through the song phrase by phrase and find the password to whatever I was trying to access. That didn't happen much since I had the most commonly used ones memorized in a day or two.


In reply to Golfing password creation by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.