Skip to content

Commit

Permalink
Simplify getPartialIP()
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Jan 1, 2020
1 parent fd1ecee commit a2cb1ca
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/libraries/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,12 @@ protected static function getFingerprint(User &$user) {
*/
protected static function getPartialIP(string $ip) {
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
$r = long2ip(ip2long($ip) & 0xFFFFFF00);
return long2ip(ip2long($ip) & 0xFFFFFF00);
} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$r = inet_ntop(
substr(unpack('A16', inet_pton($ip))[1], 0, 8) . str_repeat(chr(0), 8)
);
return inet_ntop(substr(inet_pton($ip), 0, 8) . str_repeat(chr(0), 8));
} else {
throw new InvalidArgumentException('$ip is not a valid IP address');
}
return $r;
}

/**
Expand Down

0 comments on commit a2cb1ca

Please sign in to comment.