ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Flexible Random Password Generation
Submitter: Satyam Sinha (other recipes)
Last Updated: 2006/05/30
Version no: 1.0
Category:

 

Not Rated yet


Description:

This script can generate a random password between a certain minimum and maximum length.

Usage: Text Source

#!/usr/bin/perl


# Configurable Parameters 


# Modify the $chars to add/remove allowed/disallowed chars

$chars = "abcdefghijklmnopqrstuvwxyz.@$01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 

# Modify the minimum and maximum length of passwords 

$lmin = 4;
$lmax = 10;


# Non configurable Parameters 

$pass;
$pass_len = 0;

# Script 

$pass_len = rand($lmax) while ($pass_len < $lmin);
$pass.= (split(//, $chars))[rand(length $chars)] while (--$pass_len >= 0);

print "$pass";

The license for this recipe is available here.

Discussion:

The top section of the script has a "Configurable Parameters" section where variables can be specified and the script will work accordingly. Explanation of configurable parameters :

- $chars : the password will only contain letter from this set.
- $lmin : the password should be atleast this long.
- $lmax : the password should be atmost this long.

The flexibility has been provided as all password requirements are different and hence this is a bit more useful approach.



Add comment

No comments.



Highest rated recipes:

1. Breaking down a URI into ...

2. Finding Palindromes

3. Extracting HTML URL Links

4. Removing dangerous ...

5. Matching Royal Mail ...

6. Finding URLs in text -- ...

7. Validating email ...

8. Validate Domain Names

9. Extract the Korean ...

10. Remove any HTML




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.