Friday, 16 March 2012

Auto Generate Password and User Function


Auto Generate Password and User Function 
class GeneratorComponent extends Object{
                // Numeric Array
var $_array_numeric      = array(1,2,3,4,5,6,7,8,9);
                // Alphabet Array
                var $_array_alpha            = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
                /**
                # Function                           : GeneratePassword
                # Create Date    : 02-12-2011
                # Description     : Generate password in random order.
                # Arguments                      : None
                # Return                              : Password
                */
                function GeneratePassword(){
               
                                $array_pass        =  $this->_array_numeric;
                                $array_pass_alpha          =             $this->_array_alpha;
                                $password     =  array_rand($array_pass,6);
                                $password_alpha =  array_rand($array_pass_alpha,6);
                                return   $array_pass[$password[0]].$array_pass_alpha[$password_alpha[1]].$array_pass[$password[2]].$array_pass_alpha[$password_alpha[3]].$array_pass[$password[4]].$array_pass_alpha[$password_alpha[5]];
                }
                /**
                # Function                           : GenerateUsername
                # Create Date    : 02-12-2011
                # Description     : Generate username in random order.
                # Arguments                      : None
                # Return                              : Username
                */
                function GenerateUsername(){
                                $array_name                     =  $this->_array_numeric;
                                $array_name_alpha       =             $this->_array_alpha;
                                $name     =  array_rand($array_name,6);
                                $name_alpha =  array_rand($array_name_alpha,6);

                                return   $array_name_alpha[$name[5]].$array_name_alpha[$name[4]].$array_name_alpha[$name[3]].$array_name_alpha[$name_alpha[2]].$array_name_alpha[$name[1]].$array_name_alpha[$name_alpha[0]];
                }
}

No comments:

Post a Comment