Ich versuche, eine Login-Seite basierend auf dem Tutorial unten zu erstellen: https://www.youtube.com/watch?v=lHBfyQgkiAAMögliche PHP, Volley und Android Ausgabe
ich alle Schritte befolgt und geändert Somethings, ich brauche kein Register-Taste, so änderte ich mein PHP:
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
String name = jsonResponse.getString("name");
Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
intent.putExtra("name", name);
intent.putExtra("username", username);
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);
}
ich folgende Fehlermeldung ich empfangen:
<?php
$con = mysqli_connect("my_host", "my_user", "my_password", "my_database");
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $username, $password);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["name"] = $name;
$response["username"] = $username;
$response["password"] = $password;
}
echo json_encode($response);
?>
ich den Fehler in dieser Methode empfängt
07-18 15:58:34.729 29396-29402/com.example.arthurf.tcc.app W/art: Suspending all threads took: 10.852ms
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:40)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:36)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Looper.loop(Looper.java:148)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at java.lang.reflect.Method.invoke(Native Method)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Das ist mein Repository auf Git: https://github.com/ArthurFranchetto/TCC.git
Jede Hilfe ist willkommen!
Danke
** Speichern Sie niemals Nur-Text-Passwörter! ** Bitte verwenden Sie PHP [integrierte Funktionen] (http://jayblanchard.net/proper_password_hashing_with_PHP.html), um die Passwortsicherheit zu behandeln. Wenn Sie eine PHP-Version kleiner als 5.5 verwenden, können Sie das 'password_hash()' [compatibility pack] (https://github.com/ircmaxell/password_compat) verwenden. Stellen Sie sicher, dass Sie *** [Kennwörter nicht entgehen] (http://Stackoverflow.com/q/36628418/1011527) *** oder verwenden Sie einen anderen Bereinigungsmechanismus vor dem Hashing. Wenn Sie dies tun, * ändert * das Passwort und verursacht unnötige zusätzliche Codierung. –