Refactor check_ns_login, it also had a serious bug.