Password Generator

By Ziddykins on May 15, 2014

Uploading stuff made for a programming challenge.
This generates 3 types of passwords for you, at a length you choose. (Alpha, alpha numeric, alpha numeric special).

#!/usr/bin/perl
use warnings; use strict;

print "1 - Alpha\n2 - Alpha-numeric\n3 - All\nChoice: ";
chomp(my $choice = <STDIN>);
my @picks;
if ($choice eq 1) {
  @picks = ("a" .. "z");
  push(@picks, "A" .. "Z");
} elsif ($choice eq 2) {
  @picks = ("a" .. "z");
  push(@picks, "A" .. "Z");
  push(@picks, 0 .. 9);
} else {
  @picks = ("a" .. "z");
  push(@picks, "A" .. "Z");
  push(@picks, 0 .. 9);
  push(@picks, split(//, ',./;\'[]\\`~{}|:"?!@#$%^&*()_+'));
}
print "\nHow long? ";
my $length = <STDIN>;
if ($length < 5) { 
  print "Password too short, using length of 10 instead\n";
  $length = 10;
}
my $password; my $count = 0;
while ($count < $length) {
  my $index = int(rand(scalar @picks));
  $password = $password . $picks[$index];
  $count++;
}
print "\nGenerated password: $password\n";

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.