Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

this is working in android studio .

main activity

 

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.CompoundButton;

public class MainActivity extends AppCompatActivity {
private SharedPreferences sharedpreferences;
private Editor editor;
private CheckBox check;
private boolean flag;

private EditText edit1;
private EditText edit2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

edit1 = (EditText) findViewById(R.id.editTextTextEmailAddress);
edit2 = (EditText) findViewById(R.id.editTextNumberPassword);

Button btnLogin = (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userName = edit1.getText().toString();
String userPassword = edit2.getText().toString();

if (check.isChecked()) {
// If the "remember password" checkbox is checked, save the username and password to shared preferences
editor.putString("account", userName);
editor.putString("password", userPassword);
editor.commit();
}

if (userName.equals(sharedpreferences.getString("account", "")) && userPassword.equals(sharedpreferences.getString("password", ""))) {
openActivity2();
} else {
Toast.makeText(MainActivity.this, "Wrong username and password", Toast.LENGTH_SHORT).show();
}
}
});


// Retrieve shared preferences and editor
sharedpreferences = getSharedPreferences("test", MODE_PRIVATE);
editor = sharedpreferences.edit();

// Retrieve the checkbox and set a listener
check = (CheckBox) findViewById(R.id.checkBox1);
check.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// Save the checked state of the checkbox to shared preferences
editor.putBoolean("rememberPassword", arg1);
editor.commit();
}
});

// Retrieve the rememberPassword flag from shared preferences
flag = sharedpreferences.getBoolean("rememberPassword", false);

// If rememberPassword flag is set, autofill the email and password fields
if (flag) {
edit1.setText(sharedpreferences.getString("account", ""));
edit2.setText(sharedpreferences.getString("password", ""));
check.setChecked(true);
}
}

private void openActivity2() {
Intent intent=new Intent(this, PlayerActivity2.class);
startActivity(intent);
}

}

-----

Where do I set one or some correct passwords so that it can judge whether it is true or false?
For example, the correct default password is admin@123.com, and the password is 1234. If it does not match, it is wrong.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education