Implement user login feature.

Implemented the user login feature and test cases for it.
Actually this is a refactoring of #71, and I closed original issues.

The patch includes several commits which also change some schemes and IMO some discussions are needed.