login problem

Put your problem here if it does not fit any of the other categories.

login problem

Postby elprisionero » Fri Jan 14, 2011 12:13 am

Im having troubles with login in with my app. I have these code downunder, the problem is when i wirte the wrong username/password i still get to Campaign.java class. If i write the correct username/password its the same. How come ? What im i doing wrong?

Code: Select all
package sr.android;

import sr.android.json.JsonLogin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends Activity {
   private String sUserName = null; 
   private String sPassword = null;   
   /** Called when the activity is first created. */ 

   public void onCreate(Bundle icicle) {
      // load up the layout 

      TextView regText = (TextView) findViewById(R.id.register);
      regText.setOnClickListener(new View.OnClickListener() {

         public void onClick(View v) {

            Intent intent = new Intent(Login.this, RegUser.class);


      // get the button resource in the xml file and assign it to a local variable of type Button
      Button loginButton = (Button)findViewById(R.id.login_button);   
      // this is the action listener 
      loginButton.setOnClickListener( new OnClickListener() {   
         public void onClick(View viewParam) {
            // this gets the resources in the xml file and assigns it to a local variable of type EditText 
            EditText usernameTextBox = (EditText) findViewById(R.id.txt_username); 
            EditText passwordTextBox = (EditText) findViewById(R.id.txt_password);     

            // the getText() gets the current value of the text box 
            // the toString() converts the value to String data type
            // then assigns it to a variable of type String 
            sUserName = usernameTextBox.getText().toString(); 
            sPassword = passwordTextBox.getText().toString();   
            // check if username and password not empty 

            if(sUserName.trim().length() == 0 || sPassword.trim().length() == 0){
               showAlert("Login error!", "Användarfältet och lösenordfältet måste vara ifyllda", "Ok", false);  }   
            else {         
               // display the username and the password in string format 
               if (checkLogin()) {   
                  // lagra användarnamn i persistent state 
                  // går till kampanj 
                  Intent intent = new Intent(Login.this, Campaign.class); 

               // incorrect username and password 
               else {
                  showAlert("Login error!","Fel användarnamn och lösenord", "Ok", false);
      // end of launch.setOnclickListener

   // Display warning dialog 
   private void showAlert(String title, String message, String button, boolean b) { 
      // TODO Auto-generated method stub 
      AlertDialog.Builder builder = new AlertDialog.Builder(Login.this); 
      builder.setTitle(title);  builder.setMessage(message); 
      builder.setPositiveButton(button, new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) {
   private boolean checkLogin() {   
      // post values, username and password 

      // send post values to login.php 
      JsonLogin reader = new JsonLogin( sUserName, sPassword, "login.php");
      return reader.getResult();
      // get result if username/password is valid.  }        }   


Code: Select all
package sr.android.json;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class JsonLogin extends JsonHandler {

   public JsonLogin(String username, String password, String webpage) {
      // TODO Auto-generated constructor stub
      ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();   
      nameValuePairs.add(new BasicNameValuePair("sUserName", username)); 
      nameValuePairs.add(new BasicNameValuePair("sPassword", password)); 
      nameValuePairs.add(new BasicNameValuePair("logUser", "loginUser"));
      progress(nameValuePairs, "login.php");

   public boolean getResult() {
      // TODO Auto-generated method stub
      return result.trim().length() != 0;



Code: Select all
$dbconn2 = pg_connect("host=localhost port=5432 dbname=xxxxuser=xxxxpassword=xxxx");

function loginUser( $msisdn ) {
   $u = $_POST['username'];
   $p = $_POST['password'];
   echo "Username: ".$u."
Password: ".$p;
   // generate encrypted password
   $hashPassword = md5($u.':'.$p);
   // check if the user and the password is correct.   
   $pg_query = sprintf("SELECT * FROM app_sr_user WHERE strmsisdn='%s' AND strauth='%s' ",


   echo $pg_query;   

   // write json code
    while(   $e=pg_fetch_assoc($q)) {
Junior Developer
Junior Developer
Posts: 12
Joined: Sat Dec 11, 2010 10:22 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 6 guests