android - 从 mysql 数据库中检索密码发送到 android+ java webservices 中的电子邮件

标签 android database email soap

我开发了登录表单 android 应用程序。在这里我必须实现忘记密码字段。如果我点击忘记密码 textview 然后它将转到下一个 Activity 。

下一个 Activity 将从用户那里获取电子邮件并从调用 soap webservices 的 mysql 数据库检查其验证。

我已经完成了上面的部分。

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

邮箱有效是指从mysql数据库中获取密码并将这些密码发送到有效邮箱。

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

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

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;

          }

             }

这是我的安卓代码:

        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 代码中实现提取密码发送到电子邮件?

最佳答案

使用这段代码,对你有帮助...

  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();
  }

}

关于android - 从 mysql 数据库中检索密码发送到 android+ java webservices 中的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13853090/

相关文章:

android - 为 Android 应用程序和 Django 数据库制作 RESTful http 服务?

android - 使用 Android makefile 构建系统构建 Android 应用程序测试代码时,编译器找不到 AndroidInstrumentationTestCase2

android - 在android中执行卸载任务

mysql - 来自城市表的地理位置距离 SQL

php - 在大数据集中递归搜索索引的性能

html - 如何使用电子邮件处理媒体查询/非内联样式。

java - 如何在android中永久隐藏状态栏?

android - 检查 JSON 中是否存在子对象

email - 使用 SMTP 向多个地址发送邮件 : relaying the message to different servers?

c# - 通过 Gmail SMTP 发送电子邮件无限期挂起而没有错误