MediaWiki REL1_33
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
This password hash type layers one or more parameterized password types on top of each other.
partialCrypt(ParameterizedPassword $passObj)
Finish the hashing of a partially hashed layered hash.
getDefaultParams()
Return an ordered array of default parameters for this password hash.
getDelimiter()
Returns the delimiter for the parameters inside the hash.
crypt( $password)
Hash a password and store the result in this object.
MediaWiki exception.
Helper class for password hash types that have a delimited set of parameters inside of the hash.
array $params
Named parameters that have default values for this password type.
array $args
Extra arguments that were found in the hash.
string $hash
String representation of the hash without the type.
Definition Password.php:71