Completed
Push — master ( bdc52b...f93e28 )
by Jonathan
36:53
created
src/Webtrees/Functions/Functions.php 1 patch
Braces   +27 added lines, -17 removed lines patch added patch discarded remove patch
@@ -114,16 +114,18 @@  discard block
 block discarded – undo
114 114
 		$len_chars = count($chars);
115 115
 		$token = '';
116 116
 		
117
-		for ($i = 0; $i < $length; $i++)
118
-			$token .= $chars[ mt_rand(0, $len_chars - 1) ];
117
+		for ($i = 0; $i < $length; $i++) {
118
+					$token .= $chars[ mt_rand(0, $len_chars - 1) ];
119
+		}
119 120
 		
120 121
 		# Number of 32 char chunks
121 122
 		$chunks = ceil( strlen($token) / 32 );
122 123
 		$md5token = '';
123 124
 		
124 125
 		# Run each chunk through md5
125
-		for ( $i=1; $i<=$chunks; $i++ )
126
-			$md5token .= md5( substr($token, $i * 32 - 32, 32) );
126
+		for ( $i=1; $i<=$chunks; $i++ ) {
127
+					$md5token .= md5( substr($token, $i * 32 - 32, 32) );
128
+		}
127 129
 		
128 130
 			# Trim the token
129 131
 		return substr($md5token, 0, $length);		
@@ -146,12 +148,14 @@  discard block
 block discarded – undo
146 148
 	 * @return string Encrypted and encoded text
147 149
 	 */
148 150
 	public static function encryptToSafeBase64($data){
149
-	    if(!self::isEncryptionCompatible())
150
-	        throw new \Exception('MCrypt PHP extension is required to use encryption.');
151
+	    if(!self::isEncryptionCompatible()) {
152
+	    	        throw new \Exception('MCrypt PHP extension is required to use encryption.');
153
+	    }
151 154
 	    
152 155
 		$key = 'STANDARDKEYIFNOSERVER';
153
-		if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE')))
154
-			$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
156
+		if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) {
157
+					$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
158
+		}
155 159
 		$iv = mcrypt_create_iv(self::ENCRYPTION_IV_SIZE, MCRYPT_RAND);
156 160
 		$id = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC,$iv);
157 161
 		$encrypted = base64_encode($iv.$id);
@@ -169,20 +173,24 @@  discard block
 block discarded – undo
169 173
 	 * @return string Decrypted text
170 174
 	 */
171 175
 	public static function decryptFromSafeBase64($encrypted){
172
-	    if(!self::isEncryptionCompatible())
173
-	        throw new \Exception('MCrypt PHP extension is required to use encryption.');
176
+	    if(!self::isEncryptionCompatible()) {
177
+	    	        throw new \Exception('MCrypt PHP extension is required to use encryption.');
178
+	    }
174 179
 	    
175 180
 		$key = 'STANDARDKEYIFNOSERVER';
176
-		if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE')))
177
-			$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
181
+		if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) {
182
+					$key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
183
+		}
178 184
 		$encrypted = str_replace('-', '+', $encrypted);
179 185
 		$encrypted = str_replace('_', '/', $encrypted);
180 186
 		$encrypted = str_replace('*', '=', $encrypted);
181 187
 		$encrypted = base64_decode($encrypted);
182
-		if(!$encrypted)
183
-			throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
184
-		if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) 
185
-			throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');
188
+		if(!$encrypted) {
189
+					throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.');
190
+		}
191
+		if(strlen($encrypted) < self::ENCRYPTION_IV_SIZE) {
192
+					throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.');
193
+		}
186 194
 		$iv_dec = substr($encrypted, 0, self::ENCRYPTION_IV_SIZE);
187 195
 		$encrypted = substr($encrypted, self::ENCRYPTION_IV_SIZE);
188 196
 		$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv_dec);
@@ -223,7 +231,9 @@  discard block
 block discarded – undo
223 231
 	 * @return boolean True if path valid
224 232
 	 */
225 233
 	public static function isValidPath($filename, $acceptfolder = FALSE) {		
226
-		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true;
234
+		if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) {
235
+			return true;
236
+		}
227 237
 		return false;
228 238
 	}
229 239
 	
Please login to merge, or discard this patch.