Android HTTPlogin问题


1. Does android have anything like sessions or cookies? 我应该如何“记住”用户已经进入了? 很明显,我不想每次使用我的应用程序时都要求input密码!

2. Should I hash the password before sending it to the server? 我在我的数据库中有一个用户名和密码列的表。 当我想检查login,我应该发送密码散列到服务器,如login.php?u=sled&p=34819d7beeabb9260a5c854bc85b3e44 ,或者只是像login.php?u=sled&p=mypassword这样的纯文本,并在服务器之前散列它执行身份validation

Solutions Collecting From Web of "Android HTTPlogin问题"


是。 有两种select。




另一种select(我在我的应用程序中使用这种替代方法)是在您将用户名和密码发送到服务器(例如,通过HttpPostHttpGet )后获取您的Cookie。 在你的问题你正在使用$_GET风格的login身份validation,所以我的示例代码将使用HttpGet


 HttpParams httpParams = new BasicHttpParams(); // It's always good to set how long they should try to connect. In this // this example, five seconds. HttpConnectionParams.setConnectionTimeout(httpParams, 5000); HttpConnectionParams.setSoTimeout(httpParams, 5000); DefaultHttpClient postClient = new DefaultHttpClient(httpParams); // Your url using $_GET style. final String url = ""; HttpGet httpGet = new HttpGet(url); HttpResponse response; try { // Execute your HttpGet against the server and catch the response to our // HttpResponse. response = postClient.execute(httpGet); // Check if everything went well. if(response.getStatusLine().getStatusCode() == 200) { // If so, grab the entity. HttpEntity entity = response.getEntity(); // If entity isn't null, grab the CookieStore from the response. if (entity != null) { CookieStore cookies = postClient.getCookieStore(); // Do some more stuff, this should probably be a method where you're // returning the CookieStore. } } } catch (Exception e) { } 

现在,当你有你的CookieStore ; 从中获取一个cookie列表,然后你可以使用Cookie来确定名称,域名,值等。

下次尝试访问您网站的“locking”内容时, 从Cookie信息中设置一个cookie到你的HttpURLConnection

 URL url = new URL(""); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setInstanceFollowRedirects(false); // "Host" and "Cookie" are fields in the HTTP response. Use WireShark // via your computer to determine correct header names. httpURLConnection.setRequestProperty("Host", domainOfYourCookie); httpURLConnection.setRequestProperty("Cookie", valueOfYourCookie); final int responseCode = httpURLConnection.getResponseCode(); // And get the content... 


取决于你的系统是如何devise的。 发送到服务器时必须有正确的信息。 这也取决于你如何在你的.php文件中散列你的信息。


将信息存储在SharedPreferences或其他东西中。 正如我刚才所说,如果你的login系统devise正确,你可以把它散列 – 这取决于你如何在你的.php文件中散列它。