User Tools

Site Tools


random_password_generator

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
random_password_generator [2018/12/08 12:49] – created 0.0.0.0random_password_generator [2019/01/30 11:32] (current) – external edit 127.0.0.1
Line 1: Line 1:
-====== Random_password_generator ====== 
- 
 <code> <code>
-#!/usr/bin/perl +  - !/usr/bin/perl 
-============================================================================== +  -  ============================================================================== 
-Name         : random_password.pl +  -  Name         : random_password.pl 
-Description  : Generates a random password according to specific rules +  -  Description  : Generates a random password according to specific rules 
-# +   
-Notes        : none +  -  Notes        : none 
-# +   
-Modification History +  -  Modification History 
-==================== +  -  ==================== 
-When      Who               What +  -  When      Who               What 
-========= ================= ================================================== +  -  ========= ================= ================================================== 
-16-APR-13 Stuart Barkley    Created +  -  16-APR-13 Stuart Barkley    Created 
-==============================================================================+  -  ==============================================================================
  
 $DEBUG=0; $DEBUG=0;
-my $password='';+my $password=//;
 my $RULES_PASSED=0; my $RULES_PASSED=0;
  
 sub debug { sub debug {
-    my $msg = $_[0];+    my $msg = $_[[0]];
     $DEBUG && print $msg;     $DEBUG && print $msg;
 } }
Line 27: Line 25:
  
  
-------------------- +  -  ------------------- 
-Generate a password +  -  Generate a password 
--------------------+  -  -------------------
 sub generate_password { sub generate_password {
     my ($pwlen) = @_;     my ($pwlen) = @_;
-    return `head /dev/urandom | uuencode -m - | sed -n 2p | cut -c1-\${pwlen:-12};`+    return `head /dev/urandom | uuencode -m - | sed -n 2p | cut -c1-\\${pwlen:-12};`
 } }
  
Line 46: Line 44:
  
     #1. Has to start and end with an alphabetic character     #1. Has to start and end with an alphabetic character
-    if ($password !~ m/^[A-z].*[A-z]$/) { +    if ($password !~ m/^[[A-z]].*[[A-z]]$/) { 
-       debug "$password failed rule 1\n";+       debug "$password failed rule 1\ 
 +";
        next;        next;
     }     }
Line 53: Line 52:
  
     #2. Has to contain at least 2 upper case characters     #2. Has to contain at least 2 upper case characters
-    if ($password !~ m/[A-Z].*[A-Z]/) { +    if ($password !~ m/[[A-Z]].*[[A-Z]]/) { 
-       debug "$password failed rule 2\n";+       debug "$password failed rule 2\ 
 +";
        next;        next;
     }     }
  
     #3. Has to contain at least 2 lower case characters     #3. Has to contain at least 2 lower case characters
-    if ($password !~ m/[a-z].*[a-z]/) { +    if ($password !~ m/[[a-z]].*[[a-z]]/) { 
-       debug "$password failed rule 3\n";+       debug "$password failed rule 3\ 
 +";
        next;        next;
     }     }
  
     #4. Has to contain at least 2 digits     #4. Has to contain at least 2 digits
-    if ($password !~ m/\d.*\d/) { +    if ($password !~ m/\\d.*\\d/) { 
-       debug "$password failed rule 4\n";+       debug "$password failed rule 4\ 
 +";
        next;        next;
     }     }
Line 72: Line 74:
     #5. Has to contain between 10 and 12 characters     #5. Has to contain between 10 and 12 characters
     if ($password !~ m/.{10,12}/) {     if ($password !~ m/.{10,12}/) {
-       debug "$password failed rule 5\n";+       debug "$password failed rule 5\ 
 +";
        next;        next;
     }     }
Line 81: Line 84:
  
     #6. Has to contain only printable characters     #6. Has to contain only printable characters
-    if ($password !~ m/[ -~]/) { +    if ($password !~ m/[[ -~]]/) { 
-       debug "$password failed rule 6\n";+       debug "$password failed rule 6\ 
 +";
        next;        next;
     }     }
  
     #7. Cannot contain certain special characters     #7. Cannot contain certain special characters
-    if ($password =~ m|[\/\&\*\$]|) { +    if ($password =~ m|[[\\/\\&\\*\\$]]|) { 
-       debug "$password failed rule 7\n";+       debug "$password failed rule 7\ 
 +";
        next;        next;
     }     }
Line 98: Line 103:
 print $password; print $password;
 </code> </code>
 +
random_password_generator.1544273361.txt.gz · Last modified: 2018/12/08 12:49 by 0.0.0.0

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki