Beispiel #1
0
 /**
  * El Constructor!
  *
  * @access public
  * @param int $length : The length of the password that will be generated.
  * @author Aziz Light
  */
 public function __construct()
 {
     parent::__construct();
     $this->_password_count = 0;
     if (func_num_args() == 1) {
         $length = func_get_args();
         $length = (int) $length[0];
         if ($length == 0) {
             $this->length = self::$config['length'];
         } else {
             $this->length = $length;
         }
     } elseif (($num_args = func_num_args()) > 1) {
         // FIXME: Throwing an exception might not be appropriate here...
         throw new Exception('The ' . __CLASS__ . ' constructor accepts only one argument! You passed ' . $num_args . '!!!');
     } else {
         $this->length = self::$config['length'];
     }
     // Calculate the maximum number of times a character can be repeated
     $this->chars = self::$config['chars'];
     $this->_usage_count = 1;
     while (strlen(implode('', $this->chars)) < $this->length) {
         for ($i = 0, $max = count($this->chars); $i < $max; $i++) {
             $this->chars[$i] .= self::$config['chars'][$i];
         }
         $this->_usage_count++;
     }
     $this->chars_backup = $this->chars;
 }
Beispiel #2
0
 /**
  * Parse the configuration file to retrieve the appropriate
  * configuration variables depending on the algorithm used.
  *
  * @access protected
  * @param string $algorithm : name of the algorithm used. Must match the name of the algorithm specific section in the config file.
  * @return void
  * @author Aziz Light
  */
 protected static function getConfig($algorithm)
 {
     $config = parse_ini_file(APPPATH . 'config.ini', true);
     self::$config = array_merge($config['General'], $config[$algorithm]);
     self::$config['chars'] = $config['Chars'];
     return;
 }
Beispiel #3
0
 /**
  * El Constructor!
  *
  * @access public
  * @param int|array $args : Either the length of the password that will be generated or an array of arguments to setup the passwords generation.
  * @author Aziz Light
  */
 public function __construct()
 {
     parent::__construct();
     $this->_password_count = 0;
     // validate the passed arguments
     $args = func_get_args();
     if (!empty($args)) {
         $this->validateArgs($args);
     }
     unset($args);
 }