Password.php
00001 <?php
00012 class Dsao_Hash_Password extends Dsao_Hash
00013 {
00017 protected $_password = '';
00018
00026 protected function __construct($length = 10, $algorithm = null)
00027 {
00028
00029 parent::__construct(false, $length, $algorithm);
00030
00031
00032 $this->_generatePassword();
00033 }
00034
00040 public function __toString()
00041 {
00042 return $this->getPassword();
00043 }
00044
00050 protected function _generatePassword()
00051 {
00052
00053 $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'.
00054 '!§$%&/()=?+#-_.:,;<>';
00055
00056
00057 $poolLength = strlen($pool);
00058
00059
00060 $this->_password = '';
00061
00062 $passwordValidator = new Dsao_Validate_Password();
00063
00064
00065 while (!$passwordValidator->isValid($this->_password))
00066 {
00067
00068 for ($i = 0; $i < $this->_length; $i++)
00069 {
00070 $this->_password .= $pool{mt_rand(0, $poolLength-1)};
00071 }
00072 }
00073
00074 $this->_generateHash($this->_password);
00075 }
00076
00085 public function deletePlainText()
00086 {
00087 $this->_password = '';
00088
00089 return $this;
00090 }
00091
00102 public static function factory($length = 10, $algorithm = null)
00103 {
00104 return new self($length, $algorithm);
00105 }
00106
00112 public function getPassword()
00113 {
00114 return $this->_password;
00115 }
00116 }