#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Sweden
    Posts
    384
    Rep Power
    15
    Hi all!

    Does anybody know how to generate a random password with both digits and characters?

    Regards,
    Christoffer SWEDEN
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Why? Is this for your own use or are you forcing users to use your generated password? Not code related, but I think that's a terrible idea. If people can't use a service the way they want to, they'll go elsewhere. Of course, if you're talking an intranet or other non-commercial venture where you have a captive audience it's fine.

    Look in the manual under uniqid(). What I'd do is take the user's name and pass it to uniqid() which automatically appends that to microtime(). Then pass the whole works to md5() which will be 32 characters long. Use substr() to bring it down to a manageable length. md5 hashes contain alphanumeric characters.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Sweden
    Posts
    384
    Rep Power
    15
    I would use the generated as a temporary password, the users will change it to another when they have logged in.

    Sorry I do not understand... Im kind of new in PHP... could you give me an example how to generate a password?

    Regards,
    Christoffer

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
    Why? Is this for your own use or are you forcing users to use your generated password? Not code related, but I think that's a terrible idea. If people can't use a service the way they want to, they'll go elsewhere. Of course, if you're talking an intranet or other non-commercial venture where you have a captive audience it's fine.

    Look in the manual under uniqid(). What I'd do is take the user's name and pass it to uniqid() which automatically appends that to microtime(). Then pass the whole works to md5() which will be 32 characters long. Use substr() to bring it down to a manageable length. md5 hashes contain alphanumeric characters.
    [/quote]

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Sweden
    Posts
    384
    Rep Power
    15
    I found a good script myself:

    <?php
    $syllables="ro,lan,pe,ter,ste,fan,bau,er,rol,wa,gen,ba,can,do,na,so,da,ten,tia,ke,par,ser,tok,en,tol ,bak,tof,rew,ple,bla,con,pre,ar,se,nal,ka,ser,ne,kon,bom,sak,tas,dor,kra,pol,dol ,ki,ka,so,fo,an,kri,sti,na,ju,di,bo,ris,kai,hei,mar,tin";
    $syllable_array=explode(",", $syllables);
    srand((double)microtime()*1000000);
    for ($count=1;$count<=5;$count++) {
    if (rand()%10 == 1) {
    printf("%0.0f",(rand()%50)+1);
    } else {
    printf("%s",$syllable_array[rand()%62]);
    }
    }
    ?>

    Thank you, Mark Roedel.

    Regards,
    Christoffer
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Or, if the person has selected a user name (in $user say).

    $pass=substr(md5(uniqid($user)),0,8);

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    3
    Rep Power
    0
    I'm trying to write a script that will loop through my database and replace old passwords with newly generated ones.

    I thought the below would work but it doesn't - it just retiurns the same password for each loop. Can anyone tell me how I can get nice prounceable(ish) passwords in this way - or I am I totally on the wrong track.

    TIA Tony

    Code:

    // Update the passwords
    $result = $db_query("SELECT * FROM $table");
    $numb = $db_num_rows($result);


    $pass = substr($pass, 0, $length);
    for ($i=0; $i < $numb; $i++){
    $row = $db_fetch_array($result);
    $id = $row[id];
    $password = $row[password];
    $newpass = $row[newpass];

    /* generate the new password */
    // This is the bit that doesn't work

    $length = 7;
    srand((double)microtime()*1000000);
    $vowels = array("a", "e", "i", "o", "u");
    $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");
    $num_vowels = count($vowels);
    $num_cons = count($cons);
    for($j = 0; $j < $length; $j++){
    $pass .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
    }


    Print"$password - $pass - $id<br>";
    }

  12. #7
  13. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Here's something I found that works well...

    // by Tony J. White on 1999-07-28 20:21:46 (v //1.0 for 3.0)
    // returns a random string of alphanumerics
    // $length is an integer specifying the //length of
    // the string to be returned

    function generate_passwd($length = 8)
    {
    // all the chars we want to use
    $all = explode(" ",
    "a b c d e f g h j k m n p q r s t w x y z "
    ."A B C D E F G H J K L M N P Q R S T W X Y Z "
    ."2 3 4 5 6 7 8 9");

    for($i=0;$i<$length;$i++)
    {
    srand((double)microtime()*1000000);
    $randy = rand(0, 61)
    $pass .= $all[$randy];
    }
    return $pass;
    }

Similar Threads

  1. MySQL password problems NOT root
    By braveheart in forum MySQL Help
    Replies: 2
    Last Post: February 15th, 2004, 08:18 AM
  2. password generation on user auth.
    By nacho_c in forum PHP Development
    Replies: 14
    Last Post: January 16th, 2004, 04:55 AM
  3. Replies: 1
    Last Post: January 7th, 2004, 06:41 PM
  4. want password protect?
    By CaptinKirk in forum Beginner Programming
    Replies: 4
    Last Post: December 18th, 2003, 12:00 PM
  5. [b]allow users to change random password[/b]
    By skootz in forum PHP Development
    Replies: 4
    Last Post: July 9th, 2003, 03:17 AM

IMN logo majestic logo threadwatch logo seochat tools logo