0

I want to build an app that talks to a database. Analogy would be the youtube app for example. It connects to a secure host (requires login and password), and then returns to user results based on their query.

What I need the app to do is:

  • Get user Login information (preferrably do it in a secure way and not store it unencrypted on the users phone - This is I think easily solved with GetPassword so not worried about this)
  • Once user clicks 'login' Authenticate the user on my site (no clue at all how to even research how to do this. I know where the source code for the login page from regular browser is but not sure what to do)
  • How do I do queries based on who the user is? (for example their email, and other related data).

I would love some specific examples as well as general, and if there is a tutorial for a way to get the phone app talking to a server I would love that as well. Or any other related tutorial for that matter.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
StanM
  • 827
  • 4
  • 12
  • 33
  • That is not code for an Android app. Did you tag this wrong? – Spidy Jun 30 '11 at 02:55
  • Sorry you are right, that code had no place there. I do need it in python, but that code let me know that i have to do it using httppost. I am trying to figure out how to make it work right now on the phone (most of the problem I am running into have nothing to do with this part of the code). I just recently picked up the android so it's all new (and started on python 3-4 weeks ago as well) – StanM Jun 30 '11 at 03:16

1 Answers1

1

You can use HttpPost and HttpGet requests to communicate with a server. HttpGet sends parameters in the url (ex: http://mysite.com/index.html?username=admin&password=cleartext). That is obviously not the preferred method for secure information. The HttpPost sends the data in a packet which is encrypted using https. Here's an example of sending user entered data to a web page.

    EditText usernameText = (EditText)findViewById(R.id.username);
    EditText passwordText = (EditText)findViewById(R.id.password);
    String postParameters = "u=" + usernameText.getText() + "&p=" + passwordText.getText();
    try {
        DefaultHttpClient kccClient = new DefaultHttpClient();

        HttpPost postRequest = new HttpPost("http://www.mywebsite.com/login.php");
        HttpEntity postEntity = new StringEntity(postParameters);
        postRequest.setHeader("Content-Type", "application/x-www-form-urlencoded");
        postRequest.setEntity(postEntity);

        HttpResponse postResponse = kccClient.execute(postRequest);
        HttpEntity postResponseEntity = postResponse.getEntity();

        responseText.setText(EntityUtils.toString(postResponseEntity));
    } catch(Exception e) {
        responseText.setText(e.getMessage());
    }

To use a secure connection, just change the web url to https://www.mywebsite.com/login.php.

Spidy
  • 39,723
  • 15
  • 65
  • 83