PX : code

genpasswd by drew Roberts
Download this code


<?php
// found on PX: PHP Code Exchange
// http://px.sklar.ccom
// genpasswd by Karl Grey on 2000-09-28
// modified Feb 05, 2001 by drew Roberts
// http://www.freetings.com - please visit
// did not work for me out of the box
// fixed by modifying the bottom section after the function itself
// added variable pwlwen in function so user can specify length of password
// generated.
function genpasswd () {
    
$passwd="\";
    $i=0;
    $pwlen=10;
    if (!($fd = fopen (\"/dev/urandom\", \"r\"))){
        echo \"File open failed\";
        exit;
    }  
    while($i!=$pwlen){
        $c=fread($fd,1);
        flush();
        if (ereg (\"[a-zA-Z0-9]\" ,$c)) {
            $passwd[$i]=$c;
            $i++;
        }
    }
    $passwd=implode ($passwd,\"\");       
    fclose($fd);
    return $passwd;
}
$passwd = genpasswd();
echo \"This password is $passwd<br>\";
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.