finish login and patch a mysql result bug

1. finish login logic
2. patch a mysql_free_result bug
3. add more error code