Web Design, Development & Marketing

Web Development Articles

PHP: Random Password / String Generator

The following PHP script can be used to generate a random password. You can easily change the length of the generated string as well as the characters it can consist of.

<?php
// length of generated password
$n = 8;
// characters that can be used in password
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
// generate and return the random password
function randPass($n, $chars)
{
  srand((double)microtime()*1000000);
  $m = strlen($chars);
  while($n--)
  {
    $randPassword .= substr($chars,rand()%$m,1);
  }
  return $randPassword;
}
?>

Subscribe to RSS Feed Bookmark and Share

Related Links

Related Articles / Posts

Barclaycard ePDQ CPI Integrations (27/05/2009)

HSBC XML API / CPI E-commerce Integrations (02/04/2009)

Recommended Open Source Invoicing System (25/03/2009)

Recent Recommended Links - October 2008 (03/10/2008)

Controlling PHP Register Globals Using .htaccess File (04/03/2008)