Results 1 to 3 of 3

Thread: PHP: Pronounceable password generator

  1. #1
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 23 Times in 23 Posts

    Default PHP: Pronounceable password generator

    I wrote this a while back, I bet there are cleverer ways, but this little function has done me proud.
    PHP Code:
    function generatePass($length=8$include_numbers=false)
    {     
        
    $vowels = array("a""e""i""o""u"); 
        
    $cons = array("b""c""d""g""h""j""k""l""m""n""p""r",
                        
    "s""t""u""v""w""tr""cr""br""fr""th""dr",
                              
    "ch""ph""wr""st""sp""sw""pr""sl""cl"); 
         
        
    $num_vowels count($vowels); 
        
    $num_cons count($cons); 
        
        
    $pre=$post=$password='';

        if(
    $include_numbers){
            while( ((
    $length/(strlen($pre) + strlen($post)+1)) > 2) ) {        
                if(
    rand(0,1)===0) {
                    
    $pre .= chr(rand(48,57));
                } else {
                    
    $post .= chr(rand(48,57));
                }
            }
        }
        
        
    $string_length $length -  (strlen($pre) + strlen($post));
        while(
    strlen($password)<$string_length){ 
            
    $password .= $cons[rand(0$num_cons 1)] 
                      .
    $vowels[rand(0$num_vowels 1)]; 
        } 
        return 
    $pre.substr($password0$string_length ).$post;  

    Usage:
    Specify the desired length of password, and whether you want it to include some numbers. The amount of numbers will depend upon the total password length and will be place both at the begining and end of the password.

    Examples:
    PHP Code:
    echo(generatePass(5)); 
    outputs something like:
    kotra
    PHP Code:
    echo(generatePass(5true)); 
    outputs something like:
    9beg3
    EDIT
    ____
    Can someone change the subject of this thread so that 'pronounceable' is spelt correctly! oops.

  2. #2
    Join Date
    Feb 2004
    Posts
    4,877
    Thanks
    2
    Thanked 134 Times in 113 Posts

    Default

    Quote Originally Posted by nick
    Can someone change the subject of this thread so that 'pronounceable' is spelt correctly! oops.
    Done - you can do this yourself if you go into Advanced Edit as opposed to inline AJAX editting.

    Nice code
    Warren Ashcroft
    Red Fox UK Limited - Pioneers in Internet Technology
    http://www.redfoxuk.com
    w.ashcroft [at] redfoxuk.com

    NOTE: Forum Private Messaging should not be used to contact staff with support queries.

  3. #3
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 23 Times in 23 Posts

    Default

    Quote Originally Posted by Warren Ashcroft
    Done - you can do this yourself if you go into Advanced Edit as opposed to inline AJAX editting.

    Nice code
    So you can, well I never!
    thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Any password reset problem?
    By soul in forum Sales and Service Feature Enquiries
    Replies: 6
    Last Post: 24th December 2005, 05:15 PM
  2. .htpasswd password encryption script
    By Mark Voss in forum Development Support
    Replies: 6
    Last Post: 21st June 2005, 08:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •