2

我已经开发了一个登录表单(用户名、密码和提交按钮),通过我的 android 应用程序中的soap webservices 使用MySQL 连接。在这里我忘记密码意味着我无法访问我的帐户,那么如何访问我的帐户。因此,当我忘记密码时,意味着单击忘记密码文本视图,然后进入忘记密码活动。在这里,当我输入我的电子邮件 ID 时,意味着我的密码是从 mysql 数据库中检索到的并将其发送到我的电子邮件 ID。

我该怎么办,请指导我。这是我的网络服务代码:

 public class Login {
 public String authentication(String userName,String password){

  String retrievedUserName = "";
 String retrievedPassword = "";
 String status = "";
 try{

 Class.forName("com.mysql.jdbc.Driver");
 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
 PreparedStatement statement =  con.prepareStatement("SELECT * FROM customers WHERE login = '"+userName+"'");
 ResultSet result = statement.executeQuery();

 while(result.next()){
 retrievedUserName = result.getString("login");
 retrievedPassword = result.getString("password");
 }

 if(retrievedUserName.equals(userName)&&retrievedPassword.equals(password)){
  status = "Success!";

 }

  else{
  status = "Login fail!!!";
   }

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

    }

   }

这是我的忘记密码 webservice 代码是:

    public class ForgetPassword {
    public String authentication(String Email){
    String retrievedEmail = "";
    String status = "";
    try{

    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root","");
    PreparedStatement statement =  con.prepareStatement("SELECT password FROM customers WHERE email = '"+Email+"'");
   ResultSet result = statement.executeQuery();

   while(result.next()){

retrievedEmail = retrievedEmail + result.getString("password");
     retrievedEmail = result.getString("email");
    }

     if(retrievedEmail.equals(Email)){
       status = "Your password has been sent to your email address";
       }

    else{
     status = "No such user exist";
       }
       }
      catch(Exception e){
       e.printStackTrace();
       }
     return retrievedEmail;
       }
       }

dis 是我忘记密码的安卓代码:

      public class ForgetPassword extends Activity {
      private final String NAMESPACE = "http://ws.userlogin.com";
      private final String URL = "http://192.168.1.168:8085/Login/services/ForgetPassword?wsdl";
      private final String SOAP_ACTION = "http://ws.userlogin.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.forget_password);
      Button submit = (Button) findViewById(R.id.submit);
      submit.setOnClickListener(new View.OnClickListener() {

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

        }
          });
           }

         private void loginAction(){
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
         boolean isUserValidated = true;
         EditText Email = (EditText) findViewById(R.id.email);
         String email = Email.getText().toString();


         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());
           if(status.equals("Success!"))
           {

               //   ADD  to save  and  read next time
                   String strUserName = Email.getText().toString().trim();

                   if (null == strUserName || strUserName.length() == 0)
                               {
                       //  showToast("Enter Your Name");
                     Email.setError( "Email is required!" );
         isUserValidated = false;
                   }
             }
           if(isUserValidated)
           {


                          Intent intent = new Intent(ForgetPassword.this,AndroidLoginExampleActivity.class);


                            startActivity(intent);

           }




                                  else
                                     {
                                      Intent i = new Intent(getApplicationContext(), ForgetPassword.class);
                                        startActivity(i);
                                     }
                                    }


    catch(Exception e){

           }
        }

        }

请帮助我,如何做到这一点?

4

1 回答 1

0

从 Java 发送邮件的标准方法是使用JavaMail API。该链接中的示例代码应该可以用于发送简单的消息,例如密码提醒。

于 2012-08-06T06:08:09.483 回答