2012-08-06 108 views
2

我已经开发了一个登录表单(用户名,密码和提交按钮)使用MySQL连接通过我的android应用程序中的soap web服务。在这里我忘记我的密码意味着我无法访问我的帐户,那么访问我的帐户的方式如何。所以当我忘记我的密码时,请点击忘记密码textview,然后忘记密码活动。在这里,当我输入我的电子邮件ID意味着我的密码从MySQL数据库中检索并发送给我的电子邮件ID。忘记密码发送到Android的注册电子邮件

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

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; 

    } 

    } 

这是我忘记web服务的代码是:

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是我的Android代码忘记密码:

 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){ 

      } 
     } 

     } 

请大家帮帮我,怎么样去做这个?

+1

您发布了很多代码。你需要哪些帮助?你需要哪些具体的帮助? – 2012-08-06 04:37:44

+0

如果我忘记我的密码意味着去​​忘记密码activity.here当我输入我的电子邮件ID意味着我的密码是从MySQL数据库检索并将其发送到我的电子邮件ID。 – user1575906 2012-08-06 04:42:24

+0

你需要一个按钮或者登录活动的东西,用户可以点击启动'ForgetPassword'活动。你有这样的事吗? – 2012-08-06 04:47:32

回答

0

从Java发送邮件的标准方式是JavaMail API。该链接中的示例代码应该适用于发送密码提示等简单消息。

相关问题