<?php // The letter l (lowercase L) and the number 1 // have been removed, as they can be mistaken // for each other. function RandomPass() { // Comment the first line to exclude special characters $chars = "!@#$%^&*"; $chars .= "abcdefghijkmnopqrstuvwxyz023456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; srand((double)microtime()*1000000); $i = 1; $pass = '' ; // Number of digits we'd like to have our password be $n = 8; while ($i < $n) { $num = rand() % strlen($chars); $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } // Usage $password = RandomPass(); echo "Random password is: $password"; ?>