Solarum Tech Boards Back to Solarum.com
September 10, 2010, 05:02:16 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to the Solarum Tech Boards, get in there and ask/answer some questions!
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Perl script to generate passwords  (Read 1030 times)
Laz
Solarum Admin
Administrator
Jr. Member
*****

Karma: +2/-0
Offline Offline

Posts: 59


SunLitLaz
View Profile WWW Email
« on: August 13, 2007, 10:27:40 PM »

Here is a little script I wrote to help me generate passwords.  It's a PERL script, and it generates 20 passwords as it is, although that can change easily enough.  I have it written to generate 15 character passwords, with a minimum of the following: 2 numbers, 2 upper case letters, 2 special characters, 2 lower case letters.  This ends up being some pretty touch cookies to contend with, but they get the job done.  I like generating 20 because I can looks over the list and pick one that looks good to me.  So, without further pedantic ramble on my part, here it is:

Code:
#!/usr/bin/perl

@uc=split(/,/,"A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
@lc=split(/,/,"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
@sc=split(/,/,"~,!,@,#,%,^,&,*,-,.,:");

sub rn() {
  $l=$_[0];
  $u=$_[1];
  $random = int(rand( $u-$l+1 ) ) + $l;
  return $random;
}

sub genpass() {
  my $uccnt=0;
  my $lccnt=0;
  my $sccnt=0;
  my $nmcnt=0;
  my $tpw="";

  $pwlen=0;
  while ($pwlen < 15) {
    $op = &rn(1,4);
    if ($op == 1) {
      if ($uccnt < 4) {
        $x = &rn(0,25);
        $tpw = $tpw . $uc[$x];
        $uccnt++;
      }
    } elsif ($op == 2) {
      if ($lccnt < 5) {
        $x = &rn(0,25);
        $tpw = $tpw . $lc[$x];
        $lccnt++;
      }
    } elsif ($op == 3) {
      if ($sccnt < 2) {
        $x = &rn(0,10);
        $tpw = $tpw . $sc[$x];
        $sccnt++;
      }
    } elsif ($op == 4) {
      if ($nmcnt < 4) {
        $x = &rn(1,9);
        $tpw = $tpw . $x;
        $nmcnt++;
      }
    }
    $pwlen = length($tpw);
  }
  return $tpw;
}

print "\n";
for ($a=1;$a<21;$a++) {
  $pw = &genpass();
  print "$a)\t$pw\n";
}
print "\n";

Enjoy!
Logged

Do you know what the chain of command is? It's the chain I go get and beat you with til you understand who's in rutting command here!
mack
Jr. Member
**

Karma: +0/-0
Offline Offline

Posts: 68



View Profile WWW
« Reply #1 on: August 15, 2007, 11:45:59 AM »

That's a keeper. Thanks!
Logged

He is no fool who gives up what he cannot keep to gain what he cannot lose --Jim Elliot, missionary martyr
Pages: [1]   Go Up
  Print  
 
Jump to:  

  Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC  
Page created in 0.152 seconds with 18 queries.