gpt4 book ai didi

javascript - (Android) 如何在允许用户更新密码之前进行对话询问用户当前密码?

转载 作者:行者123 更新时间:2023-12-01 23:44:12 26 4
gpt4 key购买 nike

我想制作一个应用程序来锁定应用程序。因此,在用户更新密码之前,为了安全起见,我希望用户先输入当前密码,然后再让用户更新新密码。

这是MainActivity.java

public class MainActivity extends AppCompatActivity {

update_pass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

AlertDialog.Builder builder = new AlertDialog.Builder(cn);
builder.setTitle("Enter Current Password");

// Set up the input
final EditText input = new EditText(cn);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setView(input);

// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_Text = input.getText().toString();

if(m_Text.isEmpty()){

Toast.makeText(MainActivity.this, "password can't be empty", Toast.LENGTH_LONG).show();
}

else{

int zz = db.getAllData(m_Text);
db.insertData(m_Text);

Toast.makeText(MainActivity.this, "password updated successfully " , Toast.LENGTH_LONG).show();
startActivity(new Intent(MainActivity.this,MainActivity.class));
finish();

}






}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();




}

AlertDialog.Builder builder = new AlertDialog.Builder(cn);
builder.setTitle("Enter Password");

// Set up the input
final EditText input = new EditText(cn);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setView(input);

// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_Text = input.getText().toString();

if(m_Text.isEmpty()){

Toast.makeText(MainActivity.this, "password can't be empty", Toast.LENGTH_LONG).show();
}

else{

int zz = db.deleteData(m_Text);
db.insertData(m_Text);

Toast.makeText(MainActivity.this, "password updated successfully " , Toast.LENGTH_LONG).show();
startActivity(new Intent(MainActivity.this,MainActivity.class));
finish();

}






}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();




}
});





}



// check your background services
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
Log.i ("Service status", "Running");
return true;
}
}
Log.i ("Service status", "Not running");
return false;
}



@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onStart() {
super.onStart();

if(!isAccessGranted()){
new AlertDialog.Builder(this)
.setTitle("USAGE_STATS Permission")
.setMessage("Allow USAGE_STATS Permission in Setting")
.setPositiveButton("Allow", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// action
startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
}
})
.setNegativeButton("Abort", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//
}
})
.show();
}
else if(pass.isEmpty()){


update_pass.setText("Set Password");

AlertDialog.Builder builder = new AlertDialog.Builder(cn);
builder.setTitle("Enter Password");

// Set up the input
final EditText input = new EditText(cn);
// Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
builder.setView(input);

// Set up the buttons
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
m_Text = input.getText().toString();

if(m_Text.isEmpty()){

Toast.makeText(MainActivity.this, "password can't be empty", Toast.LENGTH_LONG).show();
}
else{
boolean tt = db.insertData(m_Text);
pass.add(m_Text);
Toast.makeText(MainActivity.this, "password added successfully "+m_Text, Toast.LENGTH_LONG).show();
update_pass.setText("Update Password");

}






}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

builder.show();



}

这是Password_Database.java

public class Password_Database extends SQLiteOpenHelper {


// this is database class, database is sqlite
// embedded in android studio

// database name
public static final String DATABASE_NAME = "pass_data.db";
// table name
public static final String TABLE_NAME = "password_table";

// columns
public static final String col1 = "password";


// constructor
public Password_Database(Context context) {
super(context, DATABASE_NAME, null, 1);
// SQLiteDatabase db = this.getWritableDatabase();

}

// create table
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + "( password TEXT ) ");
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
}


// insert data into table
public boolean insertData(String name) {

SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(col1,name);


long result = db.insert(TABLE_NAME, null ,contentValues);
db.close();

if(result == -1){
return false;
}
else{
return true;
}

}


// read data from table
public Cursor getAllData(String m_Text){

SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("Select * from "+ TABLE_NAME, null);
return res;
}






// update data in table

public boolean updateData(String name, String pass){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();

db.update(TABLE_NAME,contentValues, col1+" =?", new String[]{name});
return true;
}



// delete data from table
public Integer deleteData(String name){
SQLiteDatabase db = this.getWritableDatabase();
int i = db.delete(TABLE_NAME, col1 +" =?", new String[]{name});
return i;
}




}

最佳答案

我认为拥有 SQL 数据库对于这种应用程序来说不太好。尝试使用 SharedPreferences 代替,然后让用户在 EditText 中输入他的旧密码并检查它

关于javascript - (Android) 如何在允许用户更新密码之前进行对话询问用户当前密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58246839/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com