MediaWiki  master
LayeredParameterizedPassword.php
Go to the documentation of this file.
1 <?php
34  protected function getDelimiter() {
35  return '!';
36  }
37 
38  protected function getDefaultParams() {
39  $params = [];
40 
41  foreach ( $this->config['types'] as $type ) {
42  $passObj = $this->factory->newFromType( $type );
43 
44  if ( !$passObj instanceof ParameterizedPassword ) {
45  throw new MWException( 'Underlying type must be a parameterized password.' );
46  } elseif ( $passObj->getDelimiter() === $this->getDelimiter() ) {
47  throw new MWException( 'Underlying type cannot use same delimiter as encapsulating type.' );
48  }
49 
50  $params[] = implode( $passObj->getDelimiter(), $passObj->getDefaultParams() );
51  }
52 
53  return $params;
54  }
55 
56  public function crypt( $password ) {
57  $lastHash = $password;
58  foreach ( $this->config['types'] as $i => $type ) {
59  // Construct pseudo-hash based on params and arguments
61  $passObj = $this->factory->newFromType( $type );
62 
63  $params = '';
64  $args = '';
65  if ( $this->params[$i] !== '' ) {
66  $params = $this->params[$i] . $passObj->getDelimiter();
67  }
68  if ( isset( $this->args[$i] ) && $this->args[$i] !== '' ) {
69  $args = $this->args[$i] . $passObj->getDelimiter();
70  }
71  $existingHash = ":$type:" . $params . $args . $this->hash;
72 
73  // Hash the last hash with the next type in the layer
74  $passObj = $this->factory->newFromCiphertext( $existingHash );
75  $passObj->crypt( $lastHash );
76 
77  // Move over the params and args
78  $this->params[$i] = implode( $passObj->getDelimiter(), $passObj->params );
79  $this->args[$i] = implode( $passObj->getDelimiter(), $passObj->args );
80  $lastHash = $passObj->hash;
81  }
82 
83  $this->hash = $lastHash;
84  }
85 
97  public function partialCrypt( ParameterizedPassword $passObj ) {
98  $type = $passObj->config['type'];
99  if ( $type !== $this->config['types'][0] ) {
100  throw new MWException( 'Only a hash in the first layer can be finished.' );
101  }
102 
103  // Gather info from the existing hash
104  $this->params[0] = implode( $passObj->getDelimiter(), $passObj->params );
105  $this->args[0] = implode( $passObj->getDelimiter(), $passObj->args );
106  $lastHash = $passObj->hash;
107 
108  // Layer the remaining types
109  foreach ( $this->config['types'] as $i => $type ) {
110  if ( $i == 0 ) {
111  continue;
112  };
113 
114  // Construct pseudo-hash based on params and arguments
116  $passObj = $this->factory->newFromType( $type );
117 
118  $params = '';
119  $args = '';
120  if ( $this->params[$i] !== '' ) {
121  $params = $this->params[$i] . $passObj->getDelimiter();
122  }
123  if ( isset( $this->args[$i] ) && $this->args[$i] !== '' ) {
124  $args = $this->args[$i] . $passObj->getDelimiter();
125  }
126  $existingHash = ":$type:" . $params . $args . $this->hash;
127 
128  // Hash the last hash with the next type in the layer
129  $passObj = $this->factory->newFromCiphertext( $existingHash );
130  $passObj->crypt( $lastHash );
131 
132  // Move over the params and args
133  $this->params[$i] = implode( $passObj->getDelimiter(), $passObj->params );
134  $this->args[$i] = implode( $passObj->getDelimiter(), $passObj->args );
135  $lastHash = $passObj->hash;
136  }
137 
138  $this->hash = $lastHash;
139  }
140 }
array $params
Named parameters that have default values for this password type.
partialCrypt(ParameterizedPassword $passObj)
Finish the hashing of a partially hashed layered hash.
This password hash type layers one or more parameterized password types on top of each other...
crypt( $password)
Hash a password and store the result in this object.
Helper class for password hash types that have a delimited set of parameters inside of the hash...
getDelimiter()
Returns the delimiter for the parameters inside the hash.
string $hash
String representation of the hash without the type.
Definition: Password.php:71
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
array $args
Extra arguments that were found in the hash.