How to Hide Specific Pages to Anonymous Users
The first can be done by not giving the permission to view user profiles to anonymous users. The latter is not the same page as for anonymous users that's where they login. Blocking it would prevent anyone from logging in.