You are here

function genpass_genpass in Generate Password 7.2

Generates a pretty, pretty, pretty good password.

Parameters

int $length: Length of the password. This is in addition to the base of 4 digits.

Return value

string A password.

2 calls to genpass_genpass()
genpass_admin_create_validate in ./genpass.module
Form validate function to set a password value.
genpass_admin_edit_validate in ./genpass.module
Form validate function to optionally set a password value.

File

./genpass.module, line 84
Genpass module: automatically sets strong passwords.

Code

function genpass_genpass($length = 15) {

  // This array contains the list of allowable characters for the
  // password. Note that the number 0 and the letter 'O' have been
  // removed to avoid confusion between the two. The same is true
  // of 'I', 1, and 'l'.
  $character_sets = array(
    'lower_letters' => 'abcdefghijkmnopqrstuvwxyz',
    'upper_letters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ',
    'digits' => '23456789',
    'special' => '@#$%^&()=/|[]{};<>/',
  );

  // Always include at least 1 character of each class to  ensure generated
  // passwords meet simplistic password strength rules.
  $pass = '';
  foreach ($character_sets as $character_set) {
    $pass .= _genpass_genpass_substring($character_set, 1);
  }

  // Now add length to get entropy.
  $pass .= _genpass_genpass_substring(implode('', $character_sets), $length);
  return $pass;
}