title: Login form validation in android
body: <p>I have developed one login form in Android. I have used validation here. I have to fill anyone (username or password) then my app should display <em>Success!</em> and should move to other activity. </p>
  
  <p>But, if both fields are empty, the success message should not be displayed and it should display <em>Login fail!!!</em>. </p>
  
  <p>Please help me this.</p>
  
  <p><strong>This is my webservice code:</strong></p>
  
  <pre><code>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) &amp;&amp; retrievedPassword.equals(password)) {
                  status = "Success!";
              } else {
                  status = "Login fail!!!";
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
          return status;
      }
  }
  </code></pre>
  
  <p><strong>This is validation for my android code:</strong></p>
  
  <pre><code>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!" );
          } 
      }
  </code></pre>