Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

generate password using php

Sun Nov 30, 2008 8:12 pm

The following code allow you to generate a password randomly using PHP, you can specify the length of generated password and also the length.

Code:

<?php

function generateRandpassword($size=9, $power=0) {
    
$vowels = 'aeuy';
    
$randconstant = 'bdghjmnpqrstvz';
    if (
$power & 1) {
        
$randconstant .= 'BDGHJLMNPQRSTVWXZ';
    }
    if (
$power & 2) {
        
$vowels .= "AEUY";
    }
    if (
$power & 4) {
        
$randconstant .= '23456789';
    }
    if (
$power & 8) {
        
$randconstant .= '@#$%';
    }

    
$Randpassword = '';
    
$alt = time() % 2;
    for (
$i = 0; $i < $size; $i++) {
        if (
$alt == 1) {
            
$Randpassword .= $randconstant[(rand() % strlen($randconstant))];
            
$alt = 0;
        } else {
            
$Randpassword .= $vowels[(rand() % strlen($vowels))];
            
$alt = 1;
        }
    }
    return
$Randpassword;
}

?>




Post a reply
  Related Posts  to : generate password using php
 Generate Unique Id As String     -  
 How to generate ALT+ENTER in java?     -  
 How to generate dynamic 3d pie chart in php???     -  
 how to encrypt password in jsp     -  
 Protect page using password in PHP     -  
 php Password protect a page     -  
 Input username and password in JAVA     -  
 simple password Strength checker     -  
 Password Security Manager Access File Java     -  
 Mile200: Removing Username, Password & Login from Header     -  

Topic Tags

PHP Variables