45 '' => [
'type' =>
'',
'class' => InvalidPassword::class ],
75 $config[
'type'] =
$type;
76 $this->types[
$type] = $config;
89 if ( !isset( $this->types[
$type] ) ) {
90 throw new InvalidArgumentException(
"Invalid password type $type." );
92 $this->
default =
$type;
101 return $this->default;
140 if ( $hash ===
null || $hash ===
false || $hash ===
'' ) {
142 } elseif ( $hash[0] !==
':' ) {
146 $type = substr( $hash, 1, strpos( $hash,
':', 1 ) - 1 );
147 if ( !isset( $this->types[
$type] ) ) {
148 throw new PasswordError(
"Unrecognized password hash type $type." );
151 $config = $this->types[
$type];
153 return new $config[
'class']( $this, $config, $hash );
164 if ( !isset( $this->types[
$type] ) ) {
165 throw new PasswordError(
"Unrecognized password hash type $type." );
168 $config = $this->types[
$type];
170 return new $config[
'class']( $this, $config );
184 if ( $password ===
null ) {
188 if ( $existing ===
null ) {
189 $config = $this->types[$this->default];
190 $obj =
new $config[
'class']( $this, $config );
192 $obj = clone $existing;
195 $obj->crypt( $password );
211 if ( $password->
getType() !== $this->default ) {
227 $length = max( 10, $minLength );
232 return substr(
Wikimedia\base_convert( $hex, 16, 32, $length ), -$length );
241 static $password =
null;
243 if ( $password ===
null ) {
244 $factory =
new self();
Represents an invalid password hash.
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
Show an error when any operation involving passwords fails to run.
Factory class for creating and checking Password objects.
getDefaultType()
Get the default password type.
string $default
The default PasswordHash type.
static generateRandomPasswordString( $minLength=10)
Generate a random string suitable for a password.
newFromType( $type)
Make a new default password of the given type.
needsUpdate(Password $password)
Determine whether a password object needs updating.
setDefaultType( $type)
Set the default password type.
__construct(array $config=[], $default='')
Construct a new password factory.
getTypes()
Get the list of types of passwords.
static newInvalidPassword()
Create an InvalidPassword.
array $types
Mapping of password types to classes.
newFromCiphertext( $hash)
Create a new Hash object from an existing string hash.
newFromPlaintext( $password, Password $existing=null)
Create a new Hash object from a plaintext password.
Represents a password hash for use in authentication.
getType()
Get the type name of the password.
needsUpdate()
Determine if the hash needs to be updated.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))