From d617e3b1689a0c26bdd3f1508e94dbf45aca4aef Mon Sep 17 00:00:00 2001 From: River Tarnell Date: Thu, 8 Mar 2007 16:15:51 +0000 Subject: [PATCH] Usernames which look like IPv6 addresses should not be allowed --- includes/User.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/includes/User.php b/includes/User.php index b42f1262dd..119dbf2956 100644 --- a/includes/User.php +++ b/includes/User.php @@ -357,7 +357,7 @@ class User { * @return bool */ static function isIP( $name ) { - return preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/',$name); + return preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.(?:xxx|\d{1,3})$/',$name) || User::isIPv6($name); /*return preg_match("/^ (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\. (?:[01]?\d{1,2}|2(:?[0-4]\d|5[0-5]))\. @@ -366,6 +366,27 @@ class User { $/x", $name);*/ } + /** + * Check if $name is an IPv6 IP. + */ + static function isIPv6($name) { + /* + * if it has any non-valid characters, it can't be a valid IPv6 + * address. + */ + if (preg_match("/[^:a-fA-F0-9]/", $name)) + return false; + + $parts = explode(":", $name); + if (count($parts) < 3) + return false; + foreach ($parts as $part) { + if (!preg_match("/^[0-9a-fA-F]{0,4}$/", $part)) + return false; + } + return true; + } + /** * Is the input a valid username? * -- 2.20.1