2

I have developed a login form (username,password and submit button) using a MySQL connection through soap webservices in my android application. Here I forget my password means I can't access my account, then how is access my account. So when I forget my password means click the forget password textview,then it is go to forget password activity. Here when I enter my email id means my password is retrieve from mysql database and send it to my email id.

How can I do, please guide me. This is my webservice code:

 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;

    }

   }

This is my forgetpassword webservice code is:

    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 is my android code for forget password:

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

           }
        }

        }

Please help me,how to do this?

User97693321
  • 3,348
  • 7
  • 43
  • 69
user1575906
  • 65
  • 1
  • 11
  • 1
    You posted a lot of code. What part of it do you need help with, and what specific help do you need? – Ted Hopp Aug 06 '12 at 04:37
  • if i forget my password means go to forget password activity.here when I enter my email id means my password is retrieve from mysql database and send it to my email id. – user1575906 Aug 06 '12 at 04:42
  • You need a button or something on the login activity that the user can tap to start the `ForgetPassword` activity. Do you have something like that? – Ted Hopp Aug 06 '12 at 04:47
  • yes...i have created one textview.if i click textview means it is go to forget password activity.that forget password activity have one field.that field name is email.here if i enter email means do to email send function.so i wish to know the concepts how is send email function is in this activity.how is to do – user1575906 Aug 06 '12 at 04:53
  • See [this question](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application) for how to send email from an Android application. – Ted Hopp Aug 06 '12 at 04:58
  • yes i have this code.but how is retrieve password from mysql using soap webservices and send that password is send to email use this code.how is use this code in above purpose.am unable do develop dis.please help me. – user1575906 Aug 06 '12 at 05:02
  • You want to know how to send an email to the user directly from the server? – Ted Hopp Aug 06 '12 at 05:06

1 Answers1

0

The standard way to send mail from Java is with the JavaMail API. The sample code in that link should be fine for sending a simple message like a password reminder.

Ted Hopp
  • 222,293
  • 47
  • 371
  • 489