• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Login form

krishnaveni

Well-Known Member
my current o/p is:

If I have to enter correct login details means displayed success message afterthat go to next activity

But if I have to enter the wrong login details means displayed login failed message.

Wish to need the o/p is:

If I have to enter correct login details means its directly go to next activity and shouldn't display success message.

But if I have to enter the wrong login details means the login fail message should be displayed.

i have used below code:

Webservice side:
package com.xcart;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class XcartLogin {
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/xcart432-pro","root","");
PreparedStatement statement = con.prepareStatement("SELECT * FROM xcart_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)&&!(retrievedUserName.equals("") && retrievedPassword.equals(""))){
status = "Success";

}

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

}

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

}

}

Android side code:
package com.androidlogin.ws;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.content.SharedPreferences;
import android.content.Context;
public class AndroidLoginExampleActivity extends Activity {
private static final String SPF_NAME = "vidslogin";
private static final String USERNAME = "login";
private static final String PASSWORD = "password";
private static final String PREFS_NAME = null;
CheckBox chkRememberMe;
private String login;
EditText userName,userPassword;
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/XcartLogin?wsdl";
private final String SOAP_ACTION = "http://xcart.com/authentication";
private final String METHOD_NAME = "authentication";
private String uName;
/** Called when the activity is first created. */
@Override
public void onBackPressed() {
// do something on back.

Intent intent = new Intent(getBaseContext(), AndroidLoginExampleActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
return;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
}

final TextView myTitleText = (TextView) findViewById(R.id.mytitle);
if (myTitleText != null) {
myTitleText.setText("Admin Login");
}
chkRememberMe = (CheckBox) findViewById(R.id.rempasswordcheckbox);
userName = (EditText) findViewById(R.id.tf_userName);
userPassword = (EditText) findViewById(R.id.tf_password);
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME,
Context.MODE_PRIVATE);
userName.setText(loginPreferences.getString(USERNAME, ""));
userPassword.setText(loginPreferences.getString(PASSWORD, ""));
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new View.OnClickListener() {

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

}
});
}
private void loginAction(){

boolean isUserValidated = true;
boolean isPasswordValidated = true;

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

EditText userName = (EditText) findViewById(R.id.tf_userName);
String user_Name = userName.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.tf_password);
String user_Password = userPassword.getText().toString();

//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("userName");//Define the variable name in the web service method
unameProp.setValue(user_Name);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable

//Pass value for Password variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);

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 = userName.getText().toString().trim();
String strPassword = userPassword.getText().toString().trim();

if (null == strUserName || strUserName.length() == 0)
{
// showToast("Enter Your Name");
userName.setError( "username is required!" );
isUserValidated = false;
}
if (null == strPassword || strPassword.length() == 0)
{
// showToast("Enter Your Password");
isPasswordValidated = false;
userPassword.setError( "password is required!" );
}
if(isUserValidated = true && isPasswordValidated == true)
{

if (chkRememberMe.isChecked())
{
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().putString(USERNAME, strUserName).putString(PASSWORD, strPassword).commit();
} else
{
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().clear().commit();
}
}

if(isUserValidated && isPasswordValidated)
{


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


intent.putExtra("login",userName.getText().toString());
startActivity(intent);

}

}

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



catch(Exception e){

}
}

}

Here I have to change the code on webservice side:
if(retrievedUserName.equals(userName)&&retrievedPassword.equals(password)&&!(retrievedUserName.equals("") && retrievedPassword.equals(""))){
status = "";

also change the android side means
if(status.equals(""))

Now when I have to enter my login username and password correctly, it shouldn't display success message also nothing is happened in my login form. But If I have to enter the wrong login details means displayed login failed message.please read my question and give me solution.
 
Back
Top Bottom