#!/usr/bin/perl # # randstring.pl - Generates a random string from a pattern # Copyright (C) 1998 Steven Pritchard # # This program is free software; you can redistribute it # and/or modify it under the same terms as Perl itself. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. use strict; use vars qw($foo $string @upper @lower @digit @punct @any @salt); use English; # For readability use FileHandle; @upper=("A".."Z"); @lower=("a".."z"); @digit=("0".."9"); @punct=qw(! @ # $ % ^ & * , . ; : ' " - _ + =); @any=(@upper, @lower, @digit, @punct); @salt=(@upper, @lower, @digit, ".", "/"); $string=shift; if (!$string) { &usage; exit 0; } if ($OSNAME eq "linux") # Should add tests for other systems with /dev/*random { # Read our seed from /dev/urandom my $urandom=new FileHandle " Characters in pattern must be one of the following: c Any lowercase character [a-z] C Any uppercase character [A-Z] n Any digit [0-9] ! A punctuation character [@{ [ join("",@punct) ] }] . Any of the above s A "salt" character [A-Za-z0-9./] END } sub basename { my($name)=@_; return $name=~/\// ? substr($name,(-1*length($name))+(rindex($name, "/")+1)) : $name; } sub random_string { my($pattern)=@_; my($n,$string); for ($n=0;$n