Android PHP Communication Login Session

Asked 2 years ago, Updated 2 years ago, 35 views

I am implementing login by requesting PHP with retrofit1.9.

Currently, the session ID from the Android RestAdapter is to be intercepted and stored in the preference.

builder.setRequestInterceptor(new RequestInterceptor() {
            @Override
            public void intercept(RequestFacade request) {

                request.addHeader("Authorization", "auth-value");
                request.addHeader("Accept", "application/json");
            }
        });
        clienteOkHttp.interceptors().add(new AddCookiesInterceptor());
        clienteOkHttp.interceptors().add(new ReceivedCookiesInterceptor());

If the current user inputs ID and PWD and it matches, there is no problem with the interceptor.

However, once you request it, PHP sends it to the header even if the ID and PWD are wrong, and Android holds the session ID value in the header, so if you turn off the app, you will be logged in immediately.

(When you run the app, check the preference to see if the cookie is empty and move on to the main page.)

So PHP handled it like this when the ID and PWD did not match.

session_start();
......
....

If (id,pwd match) {
 //Set session variable
}
else if {
 //id,pwd mismatch
  $_SESSION = array();
  session_destroy();
}


I didn't think this would be loaded in the header, but it's a problem because the header contains an ID value.

1. As a result, I want to empty the session ID value in the header when login fails.

2. If the ID and PWD match at login, put the ID value in the session variable and inquire the user information using the session variable. Is it right to send a user ID like this?

3. Should DB manage additional user sessions to implement redundant logins?

4. I didn't feel the need for a session on Android, not on the web, but I thought it would be necessary to have user information on the client's end like an ID and send it to the request whenever necessary. Am I right?

php android

2022-09-21 14:18

1 Answers

This is not the answer to the above code, but the answer to number 4.

Even if you send it when you log in for the first time, you can see it if you capture the packet

Even if you send it with encryption, the client has or receives the key, so if you manipulate the client, you can decrypt it and see it

So in fact, you don't really have to use a session in a bothersome app. Of course, it doesn't matter if you use it, but there are many things to pay attention to.

So, if the login is successful, issue a token and throw it to Clara.

There's a way to authenticate by sending tokens whenever a request comes

There are several ways among them, and the way I want to recommend is called JWT

http://bcho.tistory.com/999

It's detailed here. To draw it simple and simple

It's like this.

The bottom line is that you send the id and pw, but you just send it with encryption

The important thing is that we now have to have the server or client sign in to prove that it's not tampered with

There are many libraries like that, so you can take your time to find them

It's a simple explanation, so you can only understand the concept. We recommend you to find out more details.


2022-09-21 14:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.