Go to the documentation of this file.
45 '' => [
'type' =>
'',
'class' => InvalidPassword::class ],
58 foreach ( $config as
$type => $options ) {
59 $this->
register(
$type, $options );
75 public function register(
$type, array $config ) {
76 $config[
'type'] =
$type;
77 $this->types[
$type] = $config;
90 if ( !isset( $this->types[
$type] ) ) {
91 throw new InvalidArgumentException(
"Invalid password type $type." );
93 $this->
default =
$type;
113 foreach ( $config->
get(
'PasswordConfig' ) as
$type => $options ) {
114 $this->
register(
$type, $options );
141 if ( $hash ===
null || $hash ===
false || $hash ===
'' ) {
143 } elseif ( $hash[0] !==
':' ) {
147 $type = substr( $hash, 1, strpos( $hash,
':', 1 ) - 1 );
148 if ( !isset( $this->types[
$type] ) ) {
149 throw new PasswordError(
"Unrecognized password hash type $type." );
152 $config = $this->types[
$type];
154 return new $config[
'class']( $this, $config, $hash );
165 if ( !isset( $this->types[
$type] ) ) {
166 throw new PasswordError(
"Unrecognized password hash type $type." );
169 $config = $this->types[
$type];
171 return new $config[
'class']( $this, $config );
185 if ( $password ===
null ) {
189 if ( $existing ===
null ) {
191 $obj =
new $config[
'class']( $this, $config );
193 $obj = clone $existing;
196 $obj->crypt( $password );
228 $length = max( 10, $minLength );
233 return substr(
Wikimedia\base_convert( $hex, 16, 32, $length ), -$length );
242 static $password =
null;
244 if ( $password ===
null ) {
245 $factory =
new self();
newFromPlaintext( $password, Password $existing=null)
Create a new Hash object from a plaintext password.
getDefaultType()
Get the default password type.
string $default
The default PasswordHash type.
setDefaultType( $type)
Set the default password type.
Show an error when any operation involving passwords fails to run.
static generateRandomPasswordString( $minLength=10)
Generate a random string suitable for a password.
Represents an invalid password hash.
needsUpdate(Password $password)
Determine whether a password object needs updating.
__construct(array $config=[], $default='')
Construct a new password factory.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
newFromCiphertext( $hash)
Create a new Hash object from an existing string hash.
getType()
Get the type name of the password.
getTypes()
Get the list of types of passwords.
static generateHex( $chars)
Generate a run of cryptographically random data and return it in hexadecimal string format.
static newInvalidPassword()
Create an InvalidPassword.
needsUpdate()
Determine if the hash needs to be updated.
Factory class for creating and checking Password objects.
Represents a password hash for use in authentication.
array $types
Mapping of password types to classes.
newFromType( $type)
Make a new default password of the given type.