shell: Fix improper reaction when login with empty user name

Fix backend to return authentication failed if user is empty.
Fix frontend to avoid empty user name.
Some refactoring.

Fixes #940