Welcome, guest | Sign In | My Account | Store | Cart

Quite often you need to generate passwords for user authentication systems.

PHP, 24 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

function make_password($length){
    $vowels = 'aeiouy';
    $consonants = 'bdghjlmnpqrstvwxz';
    $password = '';
    
    $alt = time() % 2;
    srand(time());

    for ($i = 0; $i < $length; $i++) {
        if ($alt == 1) {
            $password .= $consonants[(rand() % 17)];
            $alt = 0;
        } else {
            $password .= $vowels[(rand() % 6)];
            $alt = 1;
        }
    }
    return $password;
}

echo make_password(8);
?>

Years ago I found this function to create pseudo-english passwords when I needed something simple for a website I was working on. I've since simplified it, but it is essentialy the same. This works by inserting a vowel in between every consonant.

5 comments

Christoph Schaper 22 years, 3 months ago  # | flag

weak passwords. to my opinion passwords containing only lower case vowels and consonants are weak passwords. generated passwords should be a mixture between lower/uppercase alphabetic chars and numbers.

maybe this function should be changed. but this is just my personal opinion

Jonathan Meyer 21 years, 7 months ago  # | flag

Strong Passwords. This function could generate strong passwords. All one needs to do is modify the $vowels and $consonants variables to include both upper and lower case letters. One could even put numbers in either of these variables.

I like this function simple and concise.

Michael Peters 21 years, 6 months ago  # | flag

Stronger Password Generation. $vowels = 'aeiouyAEIOUY' $consonants = 'bdghjlmnpqrstvwxzBDGHJLMNPQRSTVWXZ' $specials = '1234567890@#$%^$vowels = 'aeiouyAEIOUY' $consonants = 'bdghjlmnpqrstvwxzBDGHJLMNPQRSTVWXZ' $specials = '1234567890@#$%^

Alan Prescott 21 years, 5 months ago  # | flag

How about.

/**
  password = make_password

  Added the strength option to allow various levels of
  strength of password.
  =0 - default, lower case only
  and 1 - Add in uppercase consonants
  and 2 - Add in upper case vowels
  and 4 - Add in numbers
  and 8 - Add in special characters
  So 15 would give everything
**/
function make_password($length=8,$strength=0) {
  $vowels = 'aeiouy';
  $consonants = 'bdghjlmnpqrstvwxz';
  if ($strength <pre>
/**
  password = make_password

  Added the strength option to allow various levels of
  strength of password.
  =0 - default, lower case only
  and 1 - Add in uppercase consonants
  and 2 - Add in upper case vowels
  and 4 - Add in numbers
  and 8 - Add in special characters
  So 15 would give everything
**/
function make_password($length=8,$strength=0) {
  $vowels = 'aeiouy';
  $consonants = 'bdghjlmnpqrstvwxz';
  if ($strength

</pre>

Alan Prescott 21 years, 5 months ago  # | flag

Sorry about that. The posting went haywire - I think ActiveState have a problem with submitting comments. - Alan

Created by Shane Caraveo on Fri, 7 Dec 2001 (MIT)
PHP recipes (51)
Shane Caraveo's recipes (5)

Required Modules

  • (none specified)

Other Information and Tasks