-3

Here is a list of random passwords:

xFn2zhgH
NqnzZtJQ
3Lh4nBkf
N8zyq4TF
wRzZTxDV
yJhL6CFH
3KdgtRX4
ypgGXdY2
Y9zN7cn2
zcy8LKNp

I need to have some kind of function that will create a password similar to the format of these existing passwords. Any suggestions for how to accomplish this?

Thanks.

Supericy
  • 5,866
  • 1
  • 21
  • 25
DanielAttard
  • 3,467
  • 9
  • 55
  • 104
  • $password = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); – TURTLE Mar 15 '13 at 11:41

3 Answers3

2
function create_password ($len)
{
  $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  $str = '';
  for ($i=0; $i < $len; $i++)
  {
    $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  }
  return $str;


}
jmadsen
  • 3,635
  • 2
  • 33
  • 49
2

Use a hash with the current date/time

$hash = md5(date('l jS \of F Y h:i:s A'));

Then truncate it to the number of chars you want.

Josh Austin
  • 740
  • 3
  • 14
  • 1
    The current date time is *not* "random" and thus this solution can be exploited. –  Feb 06 '13 at 03:23
1

If you need it in PHP, here is a simple code to generate random password:

function randomPassword($length = 8) {
    $password = '';
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $limit = strlen($characters) - 1;
    for ($i = 0; $i < $length; $i++) {
        $password .= $characters[rand(0, $limit)];
    }
    return $password;
}
Code-Source
  • 2,215
  • 19
  • 13