MediaWiki  REL1_24
ParameterizedPassword.php
Go to the documentation of this file.
00001 <?php
00038 abstract class ParameterizedPassword extends Password {
00043     protected $params = array();
00044 
00050     protected $args = array();
00051 
00052     protected function parseHash( $hash ) {
00053         parent::parseHash( $hash );
00054 
00055         if ( $hash === null ) {
00056             $this->params = $this->getDefaultParams();
00057             return;
00058         }
00059 
00060         $parts = explode( $this->getDelimiter(), $hash );
00061         $paramKeys = array_keys( $this->getDefaultParams() );
00062 
00063         if ( count( $parts ) < count( $paramKeys ) ) {
00064             throw new PasswordError( 'Hash is missing required parameters.' );
00065         }
00066 
00067         if ( $paramKeys ) {
00068             $this->args = array_splice( $parts, count( $paramKeys ) );
00069             $this->params = array_combine( $paramKeys, $parts );
00070         } else {
00071             $this->args = $parts;
00072         }
00073 
00074         if ( $this->args ) {
00075             $this->hash = array_pop( $this->args );
00076         } else {
00077             $this->hash = null;
00078         }
00079     }
00080 
00081     public function needsUpdate() {
00082         return parent::needsUpdate() || $this->params !== $this->getDefaultParams();
00083     }
00084 
00085     public function toString() {
00086         return
00087             ':' . $this->config['type'] . ':' .
00088             implode( $this->getDelimiter(), array_merge( $this->params, $this->args ) ) .
00089             $this->getDelimiter() . $this->hash;
00090     }
00091 
00097     abstract protected function getDelimiter();
00098 
00114     abstract protected function getDefaultParams();
00115 }