Authenticate user the right way

Fix #1335