Advertisement
Guest User

Untitled

a guest
May 1st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. package com.example.joepc.project3;
  2.  
  3. import android.content.Intent;
  4. import android.database.Cursor;
  5. import android.os.Bundle;
  6. import android.support.design.widget.FloatingActionButton;
  7. import android.support.design.widget.Snackbar;
  8. import android.support.v7.app.AppCompatActivity;
  9. import android.support.v7.widget.Toolbar;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.EditText;
  13. import android.widget.TextView;
  14.  
  15. import net.sqlcipher.database.SQLiteDatabase;
  16.  
  17. import java.io.File;
  18.  
  19. //import com.example.joseph.project3.R;
  20.  
  21. public class MyRegActivity extends AppCompatActivity {
  22.  
  23. public static final String RESULT_TAG = "result_type";
  24.  
  25. @Override
  26. protected void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.activity_my_reg);
  29. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  30. setSupportActionBar(toolbar);
  31.  
  32. FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  33. fab.setOnClickListener(new View.OnClickListener() {
  34. @Override
  35. public void onClick(View view) {
  36. Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
  37. .setAction("Action", null).show();
  38. }
  39. });
  40. SQLiteDatabase.loadLibs(this);
  41. File databaseFile = getDatabasePath(TableItems.DB_NAME_FULL);
  42. final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "AnyPassword",null);
  43.  
  44. Button bt = (Button) findViewById(R.id.button);
  45. bt.setOnClickListener(new View.OnClickListener() {
  46. @Override
  47. public void onClick(View view) {
  48. EditText user_name_block = (EditText) findViewById(R.id.editText_name);
  49. EditText password_block = (EditText) findViewById(R.id.editText_pwd);
  50. String username_value = user_name_block.getText().toString();
  51. String password_value = password_block.getText().toString();
  52. //TextView tv = (TextView) findViewById(R.id.tv_display);
  53. //tv.setText(username_value);
  54.  
  55. //Cursor cursor = database.rawQuery("select * from login where USERNAME = '" + username_value + "' and PASSWORD = '" + password_value + "';",null);
  56. Cursor cursor = database.rawQuery("select * from login where USERNAME = ? and PASSWORD = ?", new String[]{username_value,password_value});
  57. boolean result = false;
  58.  
  59. if(cursor !=null){
  60. if(cursor.moveToNext()){
  61. result = true;
  62. }
  63. cursor.close();
  64. }
  65.  
  66. Intent intent = new Intent();
  67. intent.putExtra(RESULT_TAG,result); //.getExtra()
  68. intent.putExtra(username_value,password_value);
  69. setResult(RESULT_OK,intent);
  70. finish();
  71. }
  72. });
  73.  
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement