Partially hide user’s username

How to particall hide user’s username for privacy purpose.

Here is how it will look like.

The script snippet

function hide_middle_username($comment_author, $comment_ID) {
    $length = strlen($comment_author);
    if ($length <= 2) {
        return $comment_author;
    }
    $first_char = substr($comment_author, 0, 1);
    $last_char = substr($comment_author, -1);
    $middle_chars = str_repeat('*', $length - 2);
    return $first_char . $middle_chars . $last_char;
}
add_filter('get_comment_author', 'hide_middle_username', 10, 2);