Hi you y'all,

I have question about looping in a perl program, please check this code. This script is much longer, but I've shrunk it to the problem part. I have a sub called random_password wich I call with:

$password = &random_password();
After that the password is inserted into the array that goes just fine, but my problem is that I don't want to use the same password (stored in the array) for all the users I insert into the database, so I think a loop or something like that must be created to generate diffrent passwords. Who can help me with this? Thanks in advance,

Avanti check me AT: dj_avanti@hotmail.com

# Sub to create a random password sub random_password { my($length, $vowels, $consonants, $alt, $s, $newchar, $i); ($length) = @_; if ($length eq "" or $length < 3) { $length = 15; # make it at least 15 chars long. } $vowels = "0000000"; $consonants = "aaaaaaaaaaaa"; srand(time() ^ ($$ + ($$ << 234)) ); $alt = int(rand(933)) - 4; $s = ""; $newchar = ""; foreach $i (0..$length-1) { if ($alt == 1) { $newchar = substr($vowels,rand(length($vowels)),1); } else { $newchar = substr($consonants, rand(length($consonants)) +,1); } $s .= $newchar; $alt = !$alt; } return $s; } sub dienice { my($msg) = @_; print "<h2>Error</h2>\n"; print $msg; exit; } # query to insert the password in the database $password = &random_password(); $sql = qq{ INSERT INTO login (login, password) VALUES ($c[1], '$passwo +rd')}; $sth = $dbh->prepare($sql); $sth->execute();

In reply to making loop in perl script by rakie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.