SHARE
TWEET

Untitled

a guest Sep 18th, 2019 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.admin.androiddatabaseexample;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.EditText;
  11. public class MainActivity extends AppCompatActivity {
  12.  private EditText etUserEmail;
  13.  private EditText etPassword;
  14.  public String username;
  15.  private String password;
  16.  String storedPassword;
  17.  Context context=this;
  18.  LoginDatabaseAdapter loginDataBaseAdapter;
  19.  @Override
  20.  protected void onCreate(Bundle savedInstanceState) {
  21.      super.onCreate(savedInstanceState);
  22.      setContentView(R.layout.activity_main);
  23.      // create the instance of Databse
  24.      loginDataBaseAdapter=new LoginDatabaseAdapter(getApplicationContext());
  25.      etUserEmail = (EditText) findViewById(R.id.Email);
  26.      etPassword = (EditText) findViewById(R.id.Password);
  27.  }
  28.  public void SignIN(View view) {
  29.    try {
  30.        loginDataBaseAdapter = loginDataBaseAdapter.open();
  31.        username = etUserEmail.getText().toString();
  32.        password = etPassword.getText().toString();
  33.        if (username.equals("") || password.equals("")) {
  34.           AlertDialog alertDialog = new AlertDialog.Builder(this).create();
  35.           alertDialog.setTitle("ALERT!");
  36.           alertDialog.setMessage("Fill All Fields");
  37.           alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  38.           public void onClick(DialogInterface dialog, int which) {
  39.           }
  40.           });
  41.           alertDialog.show();
  42.        }
  43.       // fetch the Password form database for respective user name
  44.       if (!username.equals("")) {
  45.           storedPassword = loginDataBaseAdapter.getSinlgeEntry(username);
  46.          // check if the Stored password matches with Password entered by user
  47.       if (password.equals(storedPassword)) {
  48.          Intent intent1 = new Intent(MainActivity.this, DisplayInfoActivity.class);
  49.          startActivity(intent1);
  50.          // finish();
  51.        }
  52.       else
  53.        {
  54.          AlertDialog alertDialog = new AlertDialog.Builder(this).create();
  55.          alertDialog.setTitle("ALERT!");
  56.          alertDialog.setMessage("Incorrect Username OR Password");
  57.          alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  58.        public void onClick(DialogInterface dialog, int which) {
  59.        }
  60.        });
  61.        alertDialog.show();
  62.        }
  63.        }
  64.        }
  65.     catch (Exception ex)
  66.       {
  67.       Log.e("Error", "error login");
  68.       }
  69.  }
  70.  public void SignUP(View view)
  71. {
  72.       Intent intent = new Intent(MainActivity.this, SignUp.class);
  73.       startActivity(intent);
  74.  }
  75.  @Override
  76.  protected void onDestroy()
  77. {
  78.      // TODO Auto-generated method stub
  79.      super.onDestroy();
  80.      // Close The Database
  81.       loginDataBaseAdapter.close();
  82.  }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top