Random Password Generation in a Perl One-Liner

Say you need a quick random 8 character alpha-numeric password. In sh, there isn't a $RANDOM variable and tr can give different results on different OS's. More than likely you have perl available - use it!

perl -le 'print map { (a..z,A..Z,0..9)[rand 62] } 0..pop' 8

Thanks to Chris Angell's Perl One-Liner page for this one. Do you have a better cross-platform way of doing it? Let me know!

Your rating: None Average: 2.5 (2 votes)

Comments

random passwords

$ openssl rand 6 -base64
VcT0eiM3

This is quick-and-dirty. Using -base64 to get a printable 8 character output means you're only using 6 bytes of random data, but it works anywhere you've got OpenSSL.

Hi. I like your blog. well

Hi. I like your blog. well done!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption>
  • Lines and paragraphs break automatically.

More information about formatting options