Hey guys, I have a few questions about implementing a login feature in Android.
1. Does android have anything like sessions or cookies?
How should I 'remember' that the user is loged in? Obviously I don't want to ask for the password every time my application is used!
2. Should I hash the password before sending it to the server?
I have a table in my database with a user and password column. When I want to check the login, should I send the password hashed to the server like login.php?u=sled&p=34819d7beeabb9260a5c854bc85b3e44
, or just plain text like login.php?u=sled&p=mypassword
and hash it on the server before I perform the authentication?
Yes. There are two alternatives.
Option #1:
You can use
CookieManager
to set your cookie.Option #2:
The other alternative (I'm using this alternative in one of my applications) is to grab your cookie after you've sent your username and password to the server (e.g. via
HttpPost
orHttpGet
). In your question you're using$_GET
style of your login authentication, so my sample code will be usingHttpGet
.Sample code using
HttpGet
:Now when you have your
CookieStore
; grab a list of cookies from it and after that you can useCookie
to determine the name, domain, value etc...Next time you're trying to access "locked" content of your website; set a cookie to your
HttpURLConnection
from yourCookie
information:Depends on how your system is designed. You must have correct information when sending it to your server. This also depends on how you're hashing your information in your .php file.
Store the information in a
SharedPreferences
or something. Like I said earlier, you can hash it if your login system is correctly designed - this depends on how you're hashing it in your .php file.