MediaWiki REL1_31
Password.php
Go to the documentation of this file.
1<?php
66abstract class Password {
70 protected $factory;
71
76 protected $hash;
77
82 protected $config;
83
87 const MAX_HASH_SIZE = 255;
88
101 final public function __construct( PasswordFactory $factory, array $config, $hash = null ) {
102 if ( !isset( $config['type'] ) ) {
103 throw new MWException( 'Password configuration must contain a type name.' );
104 }
105 $this->config = $config;
106 $this->factory = $factory;
107
108 if ( $hash !== null && strlen( $hash ) >= 3 ) {
109 // Strip the type from the hash for parsing
110 $hash = substr( $hash, strpos( $hash, ':', 1 ) + 1 );
111 }
112
113 $this->hash = $hash;
114 $this->parseHash( $hash );
115 }
116
122 final public function getType() {
123 return $this->config['type'];
124 }
125
133 protected function parseHash( $hash ) {
134 }
135
141 abstract public function needsUpdate();
142
153 public function equals( $other ) {
154 if ( !$other instanceof self ) {
155 // No need to use the factory because we're definitely making
156 // an object of the same type.
157 $obj = clone $this;
158 $obj->crypt( $other );
159 $other = $obj;
160 }
161
162 return hash_equals( $this->toString(), $other->toString() );
163 }
164
177 public function toString() {
178 $result = ':' . $this->config['type'] . ':' . $this->hash;
179 $this->assertIsSafeSize( $result );
180 return $result;
181 }
182
193 final protected function assertIsSafeSize( $hash ) {
194 if ( strlen( $hash ) > self::MAX_HASH_SIZE ) {
195 throw new PasswordError( "Password hash is too big" );
196 }
197 }
198
208 abstract public function crypt( $password );
209}
MediaWiki exception.
Show an error when any operation involving passwords fails to run.
Factory class for creating and checking Password objects.
Represents a password hash for use in authentication.
Definition Password.php:66
getType()
Get the type name of the password.
Definition Password.php:122
parseHash( $hash)
Perform any parsing necessary on the hash to see if the hash is valid and/or to perform logic for see...
Definition Password.php:133
crypt( $password)
Hash a password and store the result in this object.
const MAX_HASH_SIZE
Hash must fit in user_password, which is a tinyblob.
Definition Password.php:87
needsUpdate()
Determine if the hash needs to be updated.
__construct(PasswordFactory $factory, array $config, $hash=null)
Construct the Password object using a string hash.
Definition Password.php:101
assertIsSafeSize( $hash)
Assert that hash will fit in a tinyblob field.
Definition Password.php:193
string $hash
String representation of the hash without the type.
Definition Password.php:76
equals( $other)
Compare one Password object to this object.
Definition Password.php:153
toString()
Convert this hash to a string that can be stored in the database.
Definition Password.php:177
array $config
Array of configuration variables injected from the constructor.
Definition Password.php:82
PasswordFactory $factory
Factory that created the object.
Definition Password.php:70
namespace being checked & $result
Definition hooks.txt:2323