static: Don't use unportable trim() function on login page

Also refactor a bit to avoid code duplication.