2017-03-09 2 views
0

안녕하세요, 저는 등록 및 로그인이 필요한 Android 스튜디오에서 앱을 만들고 있습니다. 로그인 정보에 문제가있는 동안 내 등록이 정상적으로 작동하며 사실이 아닌 부울 값이 표시됩니다.androip 앱에서 로그인이 작동하지 않습니다

`$con = mysqli_connect("localhost", "id1013905_trhtkv", "my password",` "id1013905_user"); 


    $username = $_POST["username"]; 
    $password = $_POST["password"]; 

    $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ?"); 
    mysqli_stmt_bind_param($statement, "s", $username); 
    mysqli_stmt_execute($statement); 
    mysqli_stmt_store_result($statement); 
    mysqli_stmt_bind_result($statement, $colUserID, $colName, $colUsername, $colAge, $colPassword); 

    $response = array(); 
    $response["success"] = false; 

    while(mysqli_stmt_fetch($statement)){ 
     if (password_verify($password, $colPassword)) { 
      $response["success"] = true; 
      $response["name"] = $colName; 
      $response["age"] = $colAge; 
     } 
    } 
    echo json_encode($response); 
    ?> 

내 로그인 활동 :

package com.ben.owner.say_something; 

import android.app.AlertDialog; 
import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

import com.android.volley.RequestQueue; 
import com.android.volley.Response; 
import com.android.volley.toolbox.Volley; 

import org.json.JSONException; 
import org.json.JSONObject; 

public class LoginActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.login_activity); 

     final EditText etUsername = (EditText)findViewById(R.id.etUsername); 
     final EditText etPassword = (EditText)findViewById(R.id.etPassword); 
     final Button bLogin = (Button)findViewById(R.id.bLogin); 
     final TextView registerLink = (TextView)findViewById(R.id.tvRegisterHere); 

     registerLink.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class); 
       LoginActivity.this.startActivity(registerIntent); 
      } 
     }); 

     bLogin.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       final String username = etUsername.getText().toString(); 
       final String password = etPassword.getText().toString(); 
       final Response.Listener<String>responseListener = new Response.Listener<String>() { 
        @Override 
        public void onResponse(String response) { 
         try { 
          JSONObject jsonResponse = new JSONObject(response); 
          boolean success = jsonResponse.getBoolean("success"); 
          if (success){ 
           String name = jsonResponse.getString("name"); 
           int age = jsonResponse.getInt("age"); 
           Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class); 
           intent.putExtra("name",name); 
           intent.putExtra("username",username); 
           intent.putExtra("age",age); 
           LoginActivity.this.startActivity(intent); 

          }else{ 
           AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); 
           builder.setMessage("Login Failed") 
             .setNegativeButton("Retry", null) 
             .create() 
             .show(); 

          } 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 

        } 
       }; 
       LoginRequest loginRequest = new LoginRequest(username,password,responseListener); 
       RequestQueue queue = Volley.newRequestQueue(LoginActivity.this); 
       queue.add(loginRequest); 

      } 
     }); 

    } 
} 

그리고 내 로그인 요청 :

사용자 이름과 암호는 여기 내 PHP 파일 올바른지3210
package com.ben.owner.say_something; 

import com.android.volley.Request; 
import com.android.volley.Response; 
import com.android.volley.toolbox.StringRequest; 

import java.util.HashMap; 
import java.util.Map; 

/** 
* Created by owner on 09/03/2017. 
*/ 
public class LoginRequest extends StringRequest { 
    private static final String LOGIN_REQUEST_URL = "https://saysomething.000webhostapp.com/Login.php"; 
    private Map<String, String> params; 

    public LoginRequest(String username,String password, Response.Listener<String> listener){ 
     super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null); 
     params = new HashMap<>(); 
     params.put("username", username); 
     params.put("password", password); 

    } 

    @Override 
    public Map<String, String> getParams() { 
     return params; 
    } 
} 
+0

password_verify은 - 암호 해시와 일치하는지 확인합니다. 해당 값을 비교하십시오. –

+0

@SandeepKharat 암호가 –

+0

과 일치합니까? – Vyacheslav

답변

0

버그를 찾으려면 응답의 서버 값을 검색하는 것이 좋습니다.

나는

대신

$response = array(); 
$response["success"] = false; 

while(mysqli_stmt_fetch($statement)){ 
    if (password_verify($password, $colPassword)) { 
     $response["success"] = true; 
     $response["name"] = $colName; 
     $response["age"] = $colAge; 
    } 
} 
echo json_encode($response); 

사용

$response = array(); 
    $response["success"] = false; 
echo $statement;//or something like 
    while(mysqli_stmt_fetch($statement)){ 

     if (password_verify($password, $colPassword)) { 

echo $password; 
echo $colPassword; 
      $response["success"] = true; 
      $response["name"] = $colName; 
      $response["age"] = $colAge; 
     } 
    } 
    echo json_encode($response); 

또는 디버그 서버 측

을 의미한다. 서버 코드가 잘못되었다는 것 같습니다.

확인이 예

http://php.net/manual/en/mysqli-stmt.fetch.php

+0

그 응답이 점점 : '{ "success": false} , 그래서 나는 어떤 이유로 든 if stat에 들어 가지 않는 것 같아요. –

관련 문제