Passed
Pull Request — release-2.1 (#5077)
by Mathias
05:29
created
Sources/Subs-Compat.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -776,15 +776,15 @@
 block discarded – undo
776 776
 if (!is_callable('random_int'))
777 777
 {
778 778
 	 /**
779
-	 * Fetch a random integer between $min and $max inclusive
780
-	 *
781
-	 * @param int $min
782
-	 * @param int $max
783
-	 *
784
-	 * @throws Exception
785
-	 *
786
-	 * @return int
787
-	 */
779
+	  * Fetch a random integer between $min and $max inclusive
780
+	  *
781
+	  * @param int $min
782
+	  * @param int $max
783
+	  *
784
+	  * @throws Exception
785
+	  *
786
+	  * @return int
787
+	  */
788 788
 	function random_int($min, $max)
789 789
 	{
790 790
 		/**
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -371,7 +371,7 @@
 block discarded – undo
371 371
 					}
372 372
 
373 373
 					return (string) substr(
374
-						(string )$binary_string,
374
+						(string) $binary_string,
375 375
 						(int) $start,
376 376
 						(int) $length
377 377
 					);
Please login to merge, or discard this patch.
Sources/Subs-Password.php 1 patch
Braces   +93 added lines, -45 removed lines patch added patch discarded remove patch
@@ -18,7 +18,8 @@  discard block
 block discarded – undo
18 18
 
19 19
 namespace {
20 20
 
21
-	if (!defined('PASSWORD_DEFAULT')) {
21
+	if (!defined('PASSWORD_DEFAULT'))
22
+	{
22 23
 
23 24
 		define('PASSWORD_BCRYPT', 1);
24 25
 		define('PASSWORD_DEFAULT', PASSWORD_BCRYPT);
@@ -34,29 +35,37 @@  discard block
 block discarded – undo
34 35
 		 *
35 36
 		 * @return string|false The hashed password, or false on error.
36 37
 		 */
37
-		function password_hash($password, $algo, array $options = array()) {
38
-			if (!function_exists('crypt')) {
38
+		function password_hash($password, $algo, array $options = array())
39
+		{
40
+			if (!function_exists('crypt'))
41
+			{
39 42
 				trigger_error("Crypt must be loaded for password_hash to function", E_USER_WARNING);
40 43
 				return null;
41 44
 			}
42
-			if (!is_string($password)) {
45
+			if (!is_string($password))
46
+			{
43 47
 				trigger_error("password_hash(): Password must be a string", E_USER_WARNING);
44 48
 				return null;
45 49
 			}
46
-			if (!is_int($algo)) {
50
+			if (!is_int($algo))
51
+			{
47 52
 				trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING);
48 53
 				return null;
49 54
 			}
50
-			if (PasswordCompat\binary\_strlen($password) > 72) {
55
+			if (PasswordCompat\binary\_strlen($password) > 72)
56
+			{
51 57
 				$password = PasswordCompat\binary\_substr($password, 0, 72);
52 58
 			}
53
-			switch ($algo) {
59
+			switch ($algo)
60
+			{
54 61
 				case PASSWORD_BCRYPT:
55 62
 					// Note that this is a C constant, but not exposed to PHP, so we don't define it here.
56 63
 					$cost = 10;
57
-					if (isset($options['cost'])) {
64
+					if (isset($options['cost']))
65
+					{
58 66
 						$cost = $options['cost'];
59
-						if ($cost < 4 || $cost > 31) {
67
+						if ($cost < 4 || $cost > 31)
68
+						{
60 69
 							trigger_error(sprintf("password_hash(): Invalid bcrypt cost parameter specified: %d", $cost), E_USER_WARNING);
61 70
 							return null;
62 71
 						}
@@ -74,8 +83,10 @@  discard block
 block discarded – undo
74 83
 					return null;
75 84
 			}
76 85
 			$salt_requires_encoding = false;
77
-			if (isset($options['salt'])) {
78
-				switch (gettype($options['salt'])) {
86
+			if (isset($options['salt']))
87
+			{
88
+				switch (gettype($options['salt']))
89
+				{
79 90
 					case 'NULL':
80 91
 					case 'boolean':
81 92
 					case 'integer':
@@ -84,7 +95,8 @@  discard block
 block discarded – undo
84 95
 						$salt = (string) $options['salt'];
85 96
 						break;
86 97
 					case 'object':
87
-						if (method_exists($options['salt'], '__tostring')) {
98
+						if (method_exists($options['salt'], '__tostring'))
99
+						{
88 100
 							$salt = (string) $options['salt'];
89 101
 							break;
90 102
 						}
@@ -94,51 +106,70 @@  discard block
 block discarded – undo
94 106
 						trigger_error('password_hash(): Non-string salt parameter supplied', E_USER_WARNING);
95 107
 						return null;
96 108
 				}
97
-				if (PasswordCompat\binary\_strlen($salt) < $required_salt_len) {
109
+				if (PasswordCompat\binary\_strlen($salt) < $required_salt_len)
110
+				{
98 111
 					trigger_error(sprintf("password_hash(): Provided salt is too short: %d expecting %d", PasswordCompat\binary\_strlen($salt), $required_salt_len), E_USER_WARNING);
99 112
 					return null;
100
-				} elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt)) {
113
+				}
114
+				elseif (0 == preg_match('#^[a-zA-Z0-9./]+$#D', $salt))
115
+				{
101 116
 					$salt_requires_encoding = true;
102 117
 				}
103
-			} else {
118
+			}
119
+			else
120
+			{
104 121
 				$buffer = '';
105 122
 				$buffer_valid = false;
106
-				if (function_exists('random_bytes')) {
123
+				if (function_exists('random_bytes'))
124
+				{
107 125
 					$buffer = random_bytes($raw_salt_len);
108
-					if ($buffer) {
126
+					if ($buffer)
127
+					{
109 128
 						$buffer_valid = true;
110 129
 					}
111 130
 				}
112
-				if (!$buffer_valid && function_exists('mcrypt_create_iv') && !defined('PHALANGER')) {
131
+				if (!$buffer_valid && function_exists('mcrypt_create_iv') && !defined('PHALANGER'))
132
+				{
113 133
 					$buffer = mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM);
114
-					if ($buffer) {
134
+					if ($buffer)
135
+					{
115 136
 						$buffer_valid = true;
116 137
 					}
117 138
 				}
118
-				if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes')) {
139
+				if (!$buffer_valid && function_exists('openssl_random_pseudo_bytes'))
140
+				{
119 141
 					$buffer = openssl_random_pseudo_bytes($raw_salt_len);
120
-					if ($buffer) {
142
+					if ($buffer)
143
+					{
121 144
 						$buffer_valid = true;
122 145
 					}
123 146
 				}
124
-				if (!$buffer_valid && @is_readable('/dev/urandom')) {
147
+				if (!$buffer_valid && @is_readable('/dev/urandom'))
148
+				{
125 149
 					$f = fopen('/dev/urandom', 'r');
126 150
 					$read = PasswordCompat\binary\_strlen($buffer);
127
-					while ($read < $raw_salt_len) {
151
+					while ($read < $raw_salt_len)
152
+					{
128 153
 						$buffer .= fread($f, $raw_salt_len - $read);
129 154
 						$read = PasswordCompat\binary\_strlen($buffer);
130 155
 					}
131 156
 					fclose($f);
132
-					if ($read >= $raw_salt_len) {
157
+					if ($read >= $raw_salt_len)
158
+					{
133 159
 						$buffer_valid = true;
134 160
 					}
135 161
 				}
136
-				if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len) {
162
+				if (!$buffer_valid || PasswordCompat\binary\_strlen($buffer) < $raw_salt_len)
163
+				{
137 164
 					$bl = PasswordCompat\binary\_strlen($buffer);
138
-					for ($i = 0; $i < $raw_salt_len; $i++) {
139
-						if ($i < $bl) {
165
+					for ($i = 0; $i < $raw_salt_len; $i++)
166
+					{
167
+						if ($i < $bl)
168
+						{
140 169
 							$buffer[$i] = $buffer[$i] ^ chr($smcFunc['random_int'](0, 255));
141
-						} else {
170
+						}
171
+						else
172
+						{
142 173
 							$buffer .= chr($smcFunc['random_int'](0, 255));
143 174
 						}
144 175
 					}
@@ -146,7 +177,8 @@  discard block
 block discarded – undo
146 177
 				$salt = $buffer;
147 178
 				$salt_requires_encoding = true;
148 179
 			}
149
-			if ($salt_requires_encoding) {
180
+			if ($salt_requires_encoding)
181
+			{
150 182
 				// encode string with the Base64 variant used by crypt
151 183
 				$base64_digits =
152 184
 					'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@@ -162,7 +194,8 @@  discard block
 block discarded – undo
162 194
 
163 195
 			$ret = crypt($password, $hash);
164 196
 
165
-			if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) {
197
+			if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength)
198
+			{
166 199
 				return false;
167 200
 			}
168 201
 
@@ -185,13 +218,15 @@  discard block
 block discarded – undo
185 218
 		 *
186 219
 		 * @return array The array of information about the hash.
187 220
 		 */
188
-		function password_get_info($hash) {
221
+		function password_get_info($hash)
222
+		{
189 223
 			$return = array(
190 224
 				'algo' => 0,
191 225
 				'algoName' => 'unknown',
192 226
 				'options' => array(),
193 227
 			);
194
-			if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) {
228
+			if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60)
229
+			{
195 230
 				$return['algo'] = PASSWORD_BCRYPT;
196 231
 				$return['algoName'] = 'bcrypt';
197 232
 				list($cost) = sscanf($hash, "$2y$%d$");
@@ -211,15 +246,19 @@  discard block
 block discarded – undo
211 246
 		 *
212 247
 		 * @return boolean True if the password needs to be rehashed.
213 248
 		 */
214
-		function password_needs_rehash($hash, $algo, array $options = array()) {
249
+		function password_needs_rehash($hash, $algo, array $options = array())
250
+		{
215 251
 			$info = password_get_info($hash);
216
-			if ($info['algo'] != $algo) {
252
+			if ($info['algo'] != $algo)
253
+			{
217 254
 				return true;
218 255
 			}
219
-			switch ($algo) {
256
+			switch ($algo)
257
+			{
220 258
 				case PASSWORD_BCRYPT:
221 259
 					$cost = isset($options['cost']) ? $options['cost'] : 10;
222
-					if ($cost != $info['options']['cost']) {
260
+					if ($cost != $info['options']['cost'])
261
+					{
223 262
 						return true;
224 263
 					}
225 264
 					break;
@@ -235,21 +274,26 @@  discard block
 block discarded – undo
235 274
 		 *
236 275
 		 * @return boolean If the password matches the hash
237 276
 		 */
238
-		function password_verify($password, $hash) {
239
-			if (!function_exists('crypt')) {
277
+		function password_verify($password, $hash)
278
+		{
279
+			if (!function_exists('crypt'))
280
+			{
240 281
 				trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
241 282
 				return false;
242 283
 			}
243
-			if (PasswordCompat\binary\_strlen($password) > 72) {
284
+			if (PasswordCompat\binary\_strlen($password) > 72)
285
+			{
244 286
 				$password = PasswordCompat\binary\_substr($password, 0, 72);
245 287
 			}
246 288
 			$ret = crypt($password, $hash);
247
-			if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13) {
289
+			if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != PasswordCompat\binary\_strlen($hash) || PasswordCompat\binary\_strlen($ret) <= 13)
290
+			{
248 291
 				return false;
249 292
 			}
250 293
 
251 294
 			$status = 0;
252
-			for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++) {
295
+			for ($i = 0; $i < PasswordCompat\binary\_strlen($ret); $i++)
296
+			{
253 297
 				$status |= (ord($ret[$i]) ^ ord($hash[$i]));
254 298
 			}
255 299
 
@@ -271,8 +315,10 @@  discard block
 block discarded – undo
271 315
 	 * @internal
272 316
 	 * @return int The number of bytes
273 317
 	 */
274
-	function _strlen($binary_string) {
275
-		if (function_exists('mb_strlen')) {
318
+	function _strlen($binary_string)
319
+	{
320
+		if (function_exists('mb_strlen'))
321
+		{
276 322
 			return mb_strlen($binary_string, '8bit');
277 323
 		}
278 324
 		return strlen($binary_string);
@@ -290,8 +336,10 @@  discard block
 block discarded – undo
290 336
 	 * @internal
291 337
 	 * @return string The substring
292 338
 	 */
293
-	function _substr($binary_string, $start, $length) {
294
-		if (function_exists('mb_substr')) {
339
+	function _substr($binary_string, $start, $length)
340
+	{
341
+		if (function_exists('mb_substr'))
342
+		{
295 343
 			return mb_substr($binary_string, $start, $length, '8bit');
296 344
 		}
297 345
 		return substr($binary_string, $start, $length);
Please login to merge, or discard this patch.
Sources/Subs-Members.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 		'member_name' => $regOptions['username'],
587 587
 		'email_address' => $regOptions['email'],
588 588
 		'passwd' => hash_password($regOptions['username'], $regOptions['password']),
589
-		'password_salt' => substr(md5($smcFunc['random_int']()), 0, 4) ,
589
+		'password_salt' => substr(md5($smcFunc['random_int']()), 0, 4),
590 590
 		'posts' => 0,
591 591
 		'date_registered' => time(),
592 592
 		'member_ip' => $regOptions['interface'] == 'admin' ? '127.0.0.1' : $user_info['ip'],
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 		'time_offset',
677 677
 	);
678 678
 	$knownInets = array(
679
-		'member_ip','member_ip2',
679
+		'member_ip', 'member_ip2',
680 680
 	);
681 681
 
682 682
 	// Call an optional function to validate the users' input.
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 	$checkName = strtr($name, array('_' => '\\_', '%' => '\\%'));
905 905
 
906 906
 	//when we got no wildcard we can use equal -> fast
907
-	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=' );
907
+	$operator = (strpos($checkName, '%') || strpos($checkName, '_') ? 'LIKE' : '=');
908 908
 
909 909
 	// Make sure they don't want someone else's name.
910 910
 	$request = $smcFunc['db_query']('', '
@@ -1273,7 +1273,7 @@  discard block
 block discarded – undo
1273 1273
 		$user_info['buddies'][] = $userReceiver;
1274 1274
 
1275 1275
 		// And add a nice alert. Don't abuse though!
1276
-		if ((cache_get_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, 86400)) == null)
1276
+		if ((cache_get_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, 86400)) == null)
1277 1277
 		{
1278 1278
 			$smcFunc['db_insert']('insert',
1279 1279
 				'{db_prefix}background_tasks',
@@ -1288,7 +1288,7 @@  discard block
 block discarded – undo
1288 1288
 			);
1289 1289
 
1290 1290
 			// Store this in a cache entry to avoid creating multiple alerts. Give it a long life cycle.
1291
-			cache_put_data('Buddy-sent-'. $user_info['id'] .'-'. $userReceiver, '1', 86400);
1291
+			cache_put_data('Buddy-sent-' . $user_info['id'] . '-' . $userReceiver, '1', 86400);
1292 1292
 		}
1293 1293
 	}
1294 1294
 
Please login to merge, or discard this patch.
Sources/Class-TOTP.php 1 patch
Braces   +24 added lines, -12 removed lines patch added patch discarded remove patch
@@ -64,7 +64,8 @@  discard block
 block discarded – undo
64 64
 	{
65 65
 		$this->buildLookup();
66 66
 
67
-		if ($initKey !== null) {
67
+		if ($initKey !== null)
68
+		{
68 69
 			$this->setInitKey($initKey);
69 70
 		}
70 71
 	}
@@ -98,7 +99,8 @@  discard block
 block discarded – undo
98 99
 	 */
99 100
 	public function setRange($range)
100 101
 	{
101
-		if (!is_numeric($range)) {
102
+		if (!is_numeric($range))
103
+		{
102 104
 			throw new \InvalidArgumentException('Invalid window range');
103 105
 		}
104 106
 		$this->range = $range;
@@ -114,7 +116,8 @@  discard block
 block discarded – undo
114 116
 	 */
115 117
 	public function setInitKey($key)
116 118
 	{
117
-		if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false) {
119
+		if (preg_match('/^[' . implode('', array_keys($this->getLookup())) . ']+$/', $key) == false)
120
+		{
118 121
 			throw new \InvalidArgumentException('Invalid base32 hash!');
119 122
 		}
120 123
 		$this->initKey = $key;
@@ -140,7 +143,8 @@  discard block
 block discarded – undo
140 143
 	 */
141 144
 	public function setLookup($lookup)
142 145
 	{
143
-		if (!is_array($lookup)) {
146
+		if (!is_array($lookup))
147
+		{
144 148
 			throw new \InvalidArgumentException('Lookup value must be an array');
145 149
 		}
146 150
 		$this->lookup = $lookup;
@@ -176,7 +180,8 @@  discard block
 block discarded – undo
176 180
 	 */
177 181
 	public function setRefresh($seconds)
178 182
 	{
179
-		if (!is_numeric($seconds)) {
183
+		if (!is_numeric($seconds))
184
+		{
180 185
 			throw new \InvalidArgumentException('Seconds must be numeric');
181 186
 		}
182 187
 		$this->refreshSeconds = $seconds;
@@ -217,7 +222,8 @@  discard block
 block discarded – undo
217 222
 	 */
218 223
 	public function validateCode($code, $initKey = null, $timestamp = null, $range = null)
219 224
 	{
220
-		if (strlen($code) !== $this->getCodeLength()) {
225
+		if (strlen($code) !== $this->getCodeLength())
226
+		{
221 227
 			throw new \InvalidArgumentException('Incorrect code length');
222 228
 		}
223 229
 
@@ -227,8 +233,10 @@  discard block
 block discarded – undo
227 233
 
228 234
 		$binary = $this->base32_decode($initKey);
229 235
 
230
-		for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++) {
231
-			if ($this->generateOneTime($binary, $time) == $code) {
236
+		for ($time = ($timestamp - $range); $time <= ($timestamp + $range); $time++)
237
+		{
238
+			if ($this->generateOneTime($binary, $time) == $code)
239
+			{
232 240
 				return true;
233 241
 			}
234 242
 		}
@@ -269,7 +277,8 @@  discard block
 block discarded – undo
269 277
 		$lookup = implode('', array_keys($this->getLookup()));
270 278
 		$code = '';
271 279
 
272
-		for ($i = 0; $i < $length; $i++) {
280
+		for ($i = 0; $i < $length; $i++)
281
+		{
273 282
 			$code .= $lookup[$smcFunc['random_int'](0, strlen($lookup) - 1)];
274 283
 		}
275 284
 
@@ -315,7 +324,8 @@  discard block
 block discarded – undo
315 324
 	{
316 325
 		$lookup = $this->getLookup();
317 326
 
318
-		if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false) {
327
+		if (preg_match('/^[' . implode('', array_keys($lookup)) . ']+$/', $hash) == false)
328
+		{
319 329
 			throw new \InvalidArgumentException('Invalid base32 hash!');
320 330
 		}
321 331
 
@@ -324,12 +334,14 @@  discard block
 block discarded – undo
324 334
 		$length = 0;
325 335
 		$binary = '';
326 336
 
327
-		for ($i = 0; $i < strlen($hash); $i++) {
337
+		for ($i = 0; $i < strlen($hash); $i++)
338
+		{
328 339
 			$buffer = $buffer << 5;
329 340
 			$buffer += $lookup[$hash[$i]];
330 341
 			$length += 5;
331 342
 
332
-			if ($length >= 8) {
343
+			if ($length >= 8)
344
+			{
333 345
 				$length -= 8;
334 346
 				$binary .= chr(($buffer & (0xFF << $length)) >> $length);
335 347
 			}
Please login to merge, or discard this patch.