使用密码检查android sdk注册表单

时间:2013-04-19 23:36:07

标签: android sdk

我需要添加所有代码,以便如果密码!=密码2然后中止注册,我不知道该怎么做,你能帮助我吗?

    httpclient=new DefaultHttpClient();
    httppost= new HttpPost("http://purelymean.com/ANDROID/adduser.php"); // make sure the url is correct.
    //add your data
    nameValuePairs = new ArrayList<NameValuePair>(4);
    // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
    nameValuePairs.add(new BasicNameValuePair("username",usern.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
    nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString().trim())); 
    nameValuePairs.add(new BasicNameValuePair("password2",password2.getText().toString().trim())); 
    nameValuePairs.add(new BasicNameValuePair("email",email.getText().toString().trim())); 

    if (password != password2) {
        Toast.makeText(Register.this,"Passwords Dont Match",Toast.LENGTH_SHORT).show();

    }

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    //Execute HTTP Post Request
    response=httpclient.execute(httppost);
    // edited by James from coderzheaven.. from here....
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    final String response = httpclient.execute(httppost, responseHandler);
    System.out.println("Response : " + response); 
    runOnUiThread(new Runnable() {
        public void run() {
            tv.setText("Response from PHP : " + response);
            dialog.dismiss();
        }
    });

1 个答案:

答案 0 :(得分:0)

不要使用密码!= password2来比较Strings.TO比较字符串我们使用String1.equals(String2)。如果此条件为假,则Toast密码不匹配并取消注册。

if (!(password.equals(password2))) {
   Toast.makeText(Register.this,"Passwords Dont Match",Toast.LENGTH_SHORT).show();
}