Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.joepc.project3;
- import android.content.Intent;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.Snackbar;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import net.sqlcipher.database.SQLiteDatabase;
- import java.io.File;
- //import com.example.joseph.project3.R;
- public class MyRegActivity extends AppCompatActivity {
- public static final String RESULT_TAG = "result_type";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_my_reg);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- }
- });
- SQLiteDatabase.loadLibs(this);
- File databaseFile = getDatabasePath(TableItems.DB_NAME_FULL);
- final SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(databaseFile, "AnyPassword",null);
- Button bt = (Button) findViewById(R.id.button);
- bt.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- EditText user_name_block = (EditText) findViewById(R.id.editText_name);
- EditText password_block = (EditText) findViewById(R.id.editText_pwd);
- String username_value = user_name_block.getText().toString();
- String password_value = password_block.getText().toString();
- //TextView tv = (TextView) findViewById(R.id.tv_display);
- //tv.setText(username_value);
- //Cursor cursor = database.rawQuery("select * from login where USERNAME = '" + username_value + "' and PASSWORD = '" + password_value + "';",null);
- Cursor cursor = database.rawQuery("select * from login where USERNAME = ? and PASSWORD = ?", new String[]{username_value,password_value});
- boolean result = false;
- if(cursor !=null){
- if(cursor.moveToNext()){
- result = true;
- }
- cursor.close();
- }
- Intent intent = new Intent();
- intent.putExtra(RESULT_TAG,result); //.getExtra()
- intent.putExtra(username_value,password_value);
- setResult(RESULT_OK,intent);
- finish();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement