Skip to main content

App Bypassing the Login-screen, even though it shouldn"t



Whenever I launch my App, even from a new emulator with now files created it still executes the bit of code, that says if the file has been created do this intent, I don't understand, it shouldn't, I have no way of testing, because I have an iPhone not an Android phone, in theory the code should not be called, only on the second time loading the app.





Thanks!





Code:







Public class LogIn extends Activity implements OnClickListener {

Button send;

EditText user;

EditText pass;

CheckBox staySignedIn;

FileOutputStream Fos;

String a;

String b;

String string = a;

String string2 = b;

String DANNYISREALLLLYYYGAAYYYYYIMNOTBS;



String FILENAME = "userandpass";



@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.login);

send = (Button) findViewById(R.id.bLogIn);

user = (EditText) findViewById(R.id.eTuser);

pass = (EditText) findViewById(R.id.eTpassword);

staySignedIn = (CheckBox) findViewById(R.id.Cbstay);

send.setOnClickListener(this);

File file = getBaseContext().getFileStreamPath(FILENAME);

if (file.exists());

Intent i = new Intent(LogIn.this, ChatService.class);

startActivity(i);}





public void onClick(View v) {

// TODO Auto-generated method stub

switch (v.getId()) {

case R.id.bLogIn:

if (pass.length() == 0)

Toast.makeText(this,

"Try to type in your username and password again!",

Toast.LENGTH_LONG).show();

else if (user.length() == 0)

Toast.makeText(this,

"Try to type in your username and password again!",

Toast.LENGTH_LONG).show();

{

if (staySignedIn.isChecked()) {



String a = user.getText().toString();

String b = pass.getText().toString();

File f = new File(FILENAME);

try {

Fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);

if (Fos != null) {

Fos.write(a.getBytes());

Fos.write(b.getBytes());

}

Fos.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

String u = user.getText().toString();

String p = pass.getText().toString();

Bundle send = new Bundle();

send.putString("key", u);

send.putString("key1", p);

Intent c = new Intent(LogIn.this, logincheck.class);

c.putExtra("key", u);

c.putExtra("key1", p);

startActivity(c);

Toast.makeText(this, "Were signing you in!", Toast.LENGTH_LONG)

.show();

if (!staySignedIn.isChecked()) {

finish();



break;

}

}

}

}











}

}

}




Comments

  1. You have a semicolon after your test:
    if (file.exists());
    Which would count as the block to run if the conditional is true. Just remove the semicolon and you should be fine.

    ReplyDelete
  2. As jbowes says remove the Semicolon there is no point that your application should crash
    if you have the code in this way

    if (file.exists())
    {
    Intent i = new Intent(LogIn.this, ChatService.class);
    startActivity(i);
    }


    If it still crashes tell me what Exception is thrown

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...