在android中重置密码

时间:2016-06-08 08:39:25

标签: php android

您好我想使用Android代码重置密码。 我试图使用此代码,我没有错误,但它不起作用。 你能帮我纠正吗?我需要你的帮助。

public class ResetPass extends AppCompatActivity{
    public static final String URL_LOG= "http://aaaaa.com/PHP/Reset.php";
    public static final String TAG_JSON_ARRAY ="result";
    private static final String TAG = "ResetPass";
    private static final int REQUEST_SIGNUP = 0;
    EditText et_email;
    Button btn_valider;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reset_pass);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        et_email = (EditText) findViewById(R.id.et_email);
        btn_valider=(Button) findViewById(R.id.btn_valider);
        btn_valider.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Reset();
            }

        });
    }
    private void Reset() {
        Log.d(TAG, "Email");
        if (!validate()) {
            onLoginFailed();
            return;
        }else{
        }
        final String email = et_email.getText().toString().trim();
        class LoginEmployee extends AsyncTask<Void,Void,String> {
            ProgressDialog loading;
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                loading = ProgressDialog.show(ResetPass.this, "Connexion...", "Veuillez patientez...", false, false);
            }
            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                loading.dismiss();
                showEmployee(s);
            }
            @Override
            protected String doInBackground(Void... v) {
                HashMap<String,String> params = new HashMap<>();
                params.put("email",email);
                //  params.put(Config.KEY_EMP_SAL,salary);
                RequestHandler rh = new RequestHandler();
                String res= rh.sendPostRequest(URL_LOG, params);
                return res;
            }
        }
        LoginEmployee le = new LoginEmployee();
        le.execute();
    }
    private void showEmployee(String json){
        try {
            JSONArray result = new JSONArray(json);
            JSONObject c = result.getJSONObject(0);
            String email = c.getString("Email");
            String d = email;
            if(d.equalsIgnoreCase(et_email.getText().toString()))
            {
                Intent intent = new Intent(this,MainActivity.class);
                intent.putExtra("email", et_email.getText().toString());
                startActivity(intent);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_SIGNUP) {
            if (resultCode == RESULT_OK) {
                this.finish();
            }
        }
    }

    @Override
    public void onBackPressed() {
        moveTaskToBack(true);
    }
    public void onLoginSuccess() {
        finish();
    }
    public void onLoginFailed() {
        Toast.makeText(ResetPass.this, "Merci de vérifier votre email", Toast.LENGTH_SHORT).show();
        btn_valider.setEnabled(true);
    }

    public boolean validate() {
        boolean valid = true;
        String email = et_email.getText().toString();

        if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            et_email.setError("entrer une adresse email valide");
            valid = false;
        } else {
            et_email.setError(null);
        }
        return valid;
    }
}

Reset.php 我使用这个PHP代码来检查数据库中电子邮件的存在。然后发送电子邮件

<?php 
        $email= $_POST['email'];
    include"dbConnect.php";
    $data=array();
    $query= SELECT * FROM membres WHERE Email='$email';
    $result   = mysql_query($query);
    $count=mysql_num_rows($result);
    if($count==1)
    {
        $rows=mysql_fetch_array($result);
        $pass  =  $rows['password'];
        $to = $rows['email'];
        $from = "Site ";
        $body  =  "Site password recovery Script
        -----------------------------------------------
        email Details is : $to;
        Here is your password  : $pass;
        Sincerely,
        Coding Cyber";
        $from = "aaaaa@gmail.com";
        $subject = "site Password recovered";
        $headers1 = "From: $from\n";
        $headers1 .= "Content-type: text/html;charset=iso-8859-1\r\n";
        $headers1 .= "X-Priority: 1\r\n";
        $headers1 .= "X-MSMail-Priority: High\r\n";
        $headers1 .= "X-Mailer: Just My Server\r\n";
        $sentmail = mail ( $to, $subject, $body, $headers1 );
    } else {
    if ($_POST ['email'] != "") {
    echo "<span style="color: #ff0000;"> Not found your email in our database</span>";
        }
        }
    if($sentmail==1)
    {
        echo "<span style='color: #ff0000;'> Your Password Has Been Sent To Your Email Address.</span>";
    }
        else
        {
        if($_POST['email']!="")
        echo "<span style='color: #ff0000;'> Cannot send password to your e-mail address.Problem with sending mail...</span>";
    }   
?>

0 个答案:

没有答案