in reply to Re: Creating random passwords?
in thread Creating random passwords?

Nice, I like it, can I just embed it like that in a script?

And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....

Replies are listed 'Best First'.
(jeffa) 3Re: Creating random passwords?
by jeffa (Bishop) on Jul 04, 2003 at 06:11 UTC
    "...can I just embed it like that in a script?"

    Umm ... no offense meant toward sauoq, but why embed that code in a script when you can use Crypt::GeneratePassword instead?

    use Crypt::GeneratePassword qw(chars); my $pwd = chars(9,16,["a".."z","A".."Z",0..9]);
    IMHO, one-liners shouldn't be embedded in a script ... they are one-liners, not scripts. I am glad that sauoq posted that one-liner though ... you should study it and understand it. But when it comes to creating applications, you don't have to reinvent wheels like that.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Umm ... no offense meant toward sauoq,

      Why would I take any offense?

      but why embed that code in a script when you can use Crypt::GeneratePassword instead?

      This is an old discussion. There are many reasons why one might choose to use a short piece of code instead of a module. And vice versa. In fact, many of them overlap. It's all a question of your priorities for the project at hand. Things to consider include maintainability, verifiability, deployability, development efficiency, run time efficiency, and compatibility among others. Even corporate culture can play a role.

      But when it comes to creating applications, you don't have to reinvent wheels like that.

      You're right, you don't. And CPAN is one of the most wonderful things about Perl. On the other hand, sometimes a custom built wheel fits better than a generic one. Fortunately, Perl gives us the tools to build those too. As for which is best, well, the only answer is: "it depends."

      Lucky for us, Perl so often gives us the choice. :-)

      -sauoq
      "My two cents aren't worth a dime.";
      
        Thanks for the good advice everyone, I'll look into and study all of those options.

        And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....
Re: Re: Re: Creating random passwords?
by sauoq (Abbot) on Jul 04, 2003 at 02:53 UTC

    Mostly. You might want to declare $p with my() and use a better variable name. I'd be inclined to put it in a sub though:

    sub generate_password { my @chars = ('a'..'z', 'A'..'Z', 0..9); my $length = 9 + rand 7 my $password = ''; $password .= $chars[rand @chars] for 1 .. $length; return $password; }

    -sauoq
    "My two cents aren't worth a dime.";