MediaWiki  REL1_24
Password.php
Go to the documentation of this file.
00001 <?php
00066 abstract class Password {
00070     protected $factory;
00071 
00076     protected $hash;
00077 
00082     protected $config;
00083 
00096     final public function __construct( PasswordFactory $factory, array $config, $hash = null ) {
00097         if ( !isset( $config['type'] ) ) {
00098             throw new MWException( 'Password configuration must contain a type name.' );
00099         }
00100         $this->config = $config;
00101         $this->factory = $factory;
00102 
00103         if ( $hash !== null && strlen( $hash ) >= 3 ) {
00104             // Strip the type from the hash for parsing
00105             $hash = substr( $hash, strpos( $hash, ':', 1 ) + 1 );
00106         }
00107 
00108         $this->hash = $hash;
00109         $this->parseHash( $hash );
00110     }
00111 
00117     final public function getType() {
00118         return $this->config['type'];
00119     }
00120 
00128     protected function parseHash( $hash ) {
00129     }
00130 
00136     public function needsUpdate() {
00137     }
00138 
00149     public function equals( $other ) {
00150         if ( !$other instanceof self ) {
00151             // No need to use the factory because we're definitely making
00152             // an object of the same type.
00153             $obj = clone $this;
00154             $obj->crypt( $other );
00155             $other = $obj;
00156         }
00157 
00158         return hash_equals( $this->toString(), $other->toString() );
00159     }
00160 
00172     public function toString() {
00173         return ':' . $this->config['type'] . ':' . $this->hash;
00174     }
00175 
00185     abstract public function crypt( $password );
00186 }