2
私は、アプリの登録とログインを、volleyの助けを借りて設定しようとしています。私は登録ページをセットアップすることができましたログイン活動に問題があります
メールとパスワードがデータベースと一致しないためです。私は私のログイン活動へのコードPHP、MySQL、Volleyを使用してAndroidログインを作成できない
package com.gjs.tablepay;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class LoginActivity extends AppCompatActivity {
EditText etxtloginemail,etxtloginpassword;
TextView txtRegister,txtforgotpass;
Button btnlogin;
PersonBean personbean;
// Is the Request to the Server
StringRequest stringRequest;
// Executes the Request
RequestQueue requestQueue;
ArrayList<PersonBean> personList;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
etxtloginemail=(EditText)findViewById(R.id.editTextloginemail);
etxtloginpassword=(EditText)findViewById(R.id.editTextloginpassword);
btnlogin=(Button)findViewById(R.id.buttonLogin);
txtRegister=(TextView)findViewById(R.id.textViewregister);
txtforgotpass=(TextView)findViewById(R.id.textViewforgotpass);
personbean = new PersonBean();
// Initialize Volley's Request Queue
requestQueue = Volley.newRequestQueue(this);
pd = new ProgressDialog(this);
txtRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,RegistrationActivity.class));
}
});
txtforgotpass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(LoginActivity.this,ForgotpassActivity.class));
}
});
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
init();
}
});}
void retrievePerson(){
pd.show();
stringRequest = new StringRequest(Request.Method.POST, Util.RETRIEVE_URL,
// success
new Response.Listener<String>() {
@Override
public void onResponse(String s) {
pd.dismiss();
Toast.makeText(LoginActivity.this,"yo",Toast.LENGTH_LONG).show();
if(s.equalsIgnoreCase("success")){
Toast.makeText(LoginActivity.this,"yo",Toast.LENGTH_LONG).show();
startActivity(new Intent(LoginActivity.this,HomeActivity.class));
}else{
pd.dismiss();
Toast.makeText(LoginActivity.this,"No Person Found",Toast.LENGTH_LONG).show();
}
}
},
// failure
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
// Toast.makeText(AllPersonsActivity.this,"Some Volley Error", Toast.LENGTH_LONG).show();
Log.i("AllPersonsActivity", volleyError.toString());
Log.i("AllPersonsActivity",volleyError.getMessage());
}
}
);
// Execute the StringRequest
requestQueue.add(stringRequest);
}
void init(){
personbean.setEmail(etxtloginemail.getText().toString().trim());
personbean.setPassword(etxtloginpassword.getText().toString().trim());
if(personbean.validateLoginPerson()){
if(Util.isNetworkConnected(this)){
retrievePerson();
}else{
Toast.makeText(this,"Please check your connectivity",Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(this,"Please Enter Details First",Toast.LENGTH_LONG).show();
}
}
}
とここに私のlogin.phpがあなたのコードで
<?php
$email=$_POST['email'];
$password=$_POST['password'];
include("dbconfig.php");
$user = @mysql_query("select uid from users where email='$email' and password='$password'");
$row = mysql_fetch_array($user,MYSQL_ASSOC);
$active = $row['active'];
$count = @mysql_num_rows($user);
$response =array();
if($count==1){
$response['success']=1;
$response['message']="Records Retrieved sucessfully";
}else{
$response['success']=0;
$response['message']="Retrieval Failure";
}
echo json_encode($response);
?>
*** [ 'mysql_ *'関数を使用して停止]にしてください(http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions -in-php)。*** [これらの拡張機能](http://php.net/manual/en/migration70.removed-exts-sapis.php)はPHP 7で削除されました。[prepared](http ://en.wikipedia.org/wiki/Prepared_statement)[PDO](http://php.net/manual/en/pdo.prepared-statements.php)と[MySQLi](http:// php。 net/manual/en/mysqli.quickstart.prepared-statements.php)、PDOの使用を検討してください(http://jayblanchard.net/demystifying_php_pdo.html)。 –
**プレーンテキストのパスワードを保存しないでください!**パスワードのセキュリティを処理するには、PHPの[組み込み関数](http://jayblanchard.net/proper_password_hashing_with_PHP.html)を使用してください。 5.5より小さいPHPバージョンを使用している場合、 'password_hash()' [互換パック](https://github.com/ircmaxell/password_compat)を使用することができます。 *** [パスワードをエスケープしない](http://stackoverflow.com/q/36628418/1011527)***を確認するか、ハッシュする前に他のクレンジングメカニズムを使用してください。パスワードを変更すると、パスワードが変更され、不要な追加のコーディングが発生します。 –
[Little Bobby](http://bobby-tables.com/)によれば*** [あなたのスクリプトはSQLインジェクション攻撃の危険にさらされています。](http://stackoverflow.com/questions/60174/how-can- i-prevent-sql-in-php)***。 [文字列をエスケープする](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)でも安全ではありません! *** SQLインジェクション!*** *それだけでは朝食だけではありません!* –