Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql数据库中检索密码将发送到android中的电子邮件+;java Web服务_Android_Database_Email_Soap - Fatal编程技术网

从mysql数据库中检索密码将发送到android中的电子邮件+;java Web服务

从mysql数据库中检索密码将发送到android中的电子邮件+;java Web服务,android,database,email,soap,Android,Database,Email,Soap,我已经开发了登录表单android应用程序。在这里,我必须实现忘记密码字段。如果我点击忘记密码textview,它将进入下一个活动 下一个活动将接收用户的电子邮件,并从调用soapwebservices的mysql数据库检查其验证 我已经完成了上面的部分 现在我必须实现以下部分: 电子邮件有效意味着从mysql数据库获取密码并将这些密码发送到有效的电子邮件 如何在java Web服务代码中实现这一部分。请帮助我。给我一些解决方案 这是我的java webservice代码,用于检查电子邮件是否有

我已经开发了登录表单android应用程序。在这里,我必须实现忘记密码字段。如果我点击忘记密码
textview
,它将进入下一个活动

下一个活动将接收用户的电子邮件,并从调用soap
webservices
的mysql数据库检查其验证

我已经完成了上面的部分

现在我必须实现以下部分:

电子邮件有效意味着从mysql数据库获取密码并将这些密码发送到有效的电子邮件

如何在java Web服务代码中实现这一部分。请帮助我。给我一些解决方案

这是我的java webservice代码,用于检查电子邮件是否有效:

public class Checkemail {
public String authentication(String Email){

String retrievedUserName = "";

String status = "";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
 PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers WHERE email = '"+Email+"'");
 ResultSet result = statement.executeQuery();

 while(result.next()){
 retrievedUserName = result.getString("email");

 }

 if(retrievedUserName.equals(Email)){
 status = "Valid Email";
 }

 else{
  status = "Invalid Email!!!";
      }

      }
        catch(Exception e){
         e.printStackTrace();
         }
       return status;

          }

             }
这是我的android代码:

        public class Login extends Activity {
       private final String NAMESPACE = "http://xcart.com";
       private final String URL = "http://10.0.0.75:8080/XcartLogin/services/Checkemail?wsdl";
       private final String SOAP_ACTION = "http://xcart.com/authentication";
       private final String METHOD_NAME = "authentication";
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.login);
       Button login = (Button) findViewById(R.id.btn_login);
       login.setOnClickListener(new View.OnClickListener() {

       public void onClick(View arg0) {
         loginAction();
         }
         });
         }

      private void loginAction(){
       SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

             EditText Email = (EditText) findViewById(R.id.tf_userName);
            String email = Email.getText().toString();


             //Pass value for userName variable of the web service
          PropertyInfo unameProp =new PropertyInfo();
           unameProp.setName("Email");//Define the variable name in the web service method
         unameProp.setValue(email);//set value for userName variable
         unameProp.setType(String.class);//Define the type of the variable
         request.addProperty(unameProp);//Pass properties to the variable
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
          try{
          androidHttpTransport.call(SOAP_ACTION, envelope);
           SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
           String status = response.toString();
           TextView result = (TextView) findViewById(R.id.tv_status);
           result.setText(response.toString());
             }
            catch(Exception e){

          }
          }
          }

如何实现在java webservice代码中获取发送到电子邮件的密码?

使用此代码。。这对你很有帮助

 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.net.Authenticator;
 import java.net.PasswordAuthentication;
 import java.net.URL;
 import java.net.URLConnection;
 import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;

  public class Connect extends Activity {
static StringBuilder sb;

   @Override
public void onCreate(Bundle savedInstanceState) {

     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);

     String strURL = "http://hostserver/";
    final String username = "username";
    final String password = "password";
    Authenticator.setDefault(new Authenticator() {
          protected PasswordAuthentication getPasswordAuthentication() {
                PasswordAuthentication pa = new PasswordAuthentication  
                                     (username, password.toCharArray());
                System.out.println(pa.getUserName() + ":" + new 
                                      String(pa.getPassword()));
                return pa;
            }
          });
    BufferedReader in = null;
    StringBuffer sb = new StringBuffer();

    try {
        URL url = new URL(strURL);
        URLConnection connection = url.openConnection();
        in = new BufferedReader(new InputStreamReader(connection
                .getInputStream()));

        String line;

        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
    } catch (java.net.ProtocolException e) {
        sb.append("User Or Password is wrong!");
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (Exception e) {
            System.out.println("Exception");
        }
    }

    Log.d("DATA", sb.toString());

}       
    }

使用此代码,它对您的帮助

  String email_id = etxt_user.getText().toString();
  SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
  request.addProperty("Email", email_id);
   Pattern EMAIL_ADDRESS_PATTERN =Pattern.compile(
         "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
         "\\@" +
         "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
         "(" +
         "\\." +
         "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
         ")+");
    Matcher matcher = EMAIL_ADDRESS_PATTERN.matcher(email_id);
    if(matcher.matches()){
     Log.v(TAG, "Your email id is valid ="+email_id);
   //  System.out.println("Your email id is valid ="+email);
    }
    else{
  //  System.out.println("enter valid email id");
  Log.v(TAG, "enter valid email id" );
   }
  SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
  soapEnvelope.dotNet = true;
  soapEnvelope.setOutputSoapObject(request);
  HttpTransportSE aht = new HttpTransportSE(URL);
  try {
    aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
    aht.call(SOAP_ACTION, soapEnvelope);
    SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
    Log.v("TAG", String.valueOf(resultsRequestSOAP));
   } catch (Exception e) {

     e.printStackTrace();
  }

}
String email_id=etxt_user.getText().toString();
SoapObject请求=新的SoapObject(名称空间、方法名称);
请求。添加属性(“电子邮件”,电子邮件id);
模式电子邮件地址模式=模式编译(
“[a-zA-Z0-9\\+\.\\\\%\-\\+]{1256}”+
"\\@" +
“[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}”+
"(" +
"\\." +
“[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}”+
")+");
Matcher Matcher=电子邮件地址模式Matcher(电子邮件id);
if(matcher.matches()){
Log.v(标记“您的电子邮件id有效=“+电子邮件id”);
//System.out.println(“您的电子邮件id有效=“+电子邮件”);
}
否则{
//System.out.println(“输入有效的电子邮件id”);
Log.v(标记“输入有效的电子邮件id”);
}
SoapSerializationEnvelope soapEnvelope=新的SoapSerializationEnvelope(soapEnvelope.VER11);
soapEnvelope.dotNet=true;
setOutputSoapObject(请求);
HttpTransportSE aht=新的HttpTransportSE(URL);
试一试{
aht.setXmlVersionTag(“”);
aht.call(SOAP\u动作,soapEnvelope);
SoapObject resultsRequestSOAP=(SoapObject)soapEnvelope.bodyIn;
Log.v(“TAG”,String.valueOf(resultsRequestSOAP));
}捕获(例外e){
e、 printStackTrace();
}
}

我必须在Web服务部分实现代码。我必须获取有效电子邮件的密码并发送到电子邮件。如果(retrievedUserName.equals(email)){status=“valid email”;在这些行之后如何获取密码我已经检查了电子邮件验证。如果电子邮件有效,则意味着如何获取密码并发送到电子邮件。如果有人忘记了密码,更好的解决方案是为他们创建一个新密码以覆盖以前的密码,而不是发送以前的密码