Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Crypt::GeneratePassword with no special characters

by Mark2117 (Initiate)
on Aug 21, 2003 at 13:00 UTC ( [id://285448]=perlquestion: print w/replies, xml ) Need Help??

Mark2117 has asked for the wisdom of the Perl Monks concerning the following question:

I apologize for such a trivial question. However, I really need to generate passwords with no special characters. I have Crypt::GeneratePassword working, however, I can not figure out how to use the chars function and restrict all special characters. I attempted the follow which was wrong:

$restrict="!@#$%^&*()_-=+/" ;
$Password=chars(5,8,0,$restrict,0);

Could someone please show me an example of how to restrict the special characters. --Mark
  • Comment on Crypt::GeneratePassword with no special characters

Replies are listed 'Best First'.
Re: Crypt::GeneratePassword with no special characters
by bm (Hermit) on Aug 21, 2003 at 13:04 UTC
    $restrict= quotemeta ("!@#$%^&*()_-=+/");
    or
    $restrict= '!@#$%^&*()_-=+/';

    --
    bm
      I am still getting the specail characters. Have I interpreted the documentation incorrectly??

      $word = chars($minlen, $maxlen [, $set , $characters, $maxcount ... ] );

      Generatess a completely random word between $minlen and $maxlen in length. If $set is given, it must be an array ref of characters to use. You can restrict occurrence of some characters by providing($characters, $maxcount) pairs, as many as you like. $characters must be a string consisting of those characters which may appear at most $maxcount times in the word.
        Yes, it looks like you are mis-interpreting.

        If $set is given, it must be an array ref of characters to use

        so this argument contains the list of chars to use, as opposed to not using. Perhaps you want:

        $Password=chars(5,8,\('a'..'z'));
        which should create a password between 5 and 8 chars in length, containing only lowercase chars from 'a' to 'z'.
        Hope this helps
        --
        bm

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://285448]
Approved by Skeeve
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found