Apply Nemory's changes

To fix reported login issues.