Skip to content

Commit f7502e1

Browse files
committed
Require old passcode to change passcode
1 parent 934500d commit f7502e1

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

app/src/main/java/org/gnucash/android/ui/passcode/PasscodePreferenceActivity.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import android.content.Intent;
2020
import android.os.Bundle;
21+
import android.preference.PreferenceManager;
2122
import android.widget.TextView;
2223
import android.widget.Toast;
2324

@@ -36,14 +37,40 @@ public class PasscodePreferenceActivity extends SherlockFragmentActivity
3637
private boolean reenter = false;
3738
private String passcode;
3839

40+
private boolean checkOldPassCode;
41+
42+
private TextView passCodeTextView;
43+
3944
@Override
4045
protected void onCreate(Bundle savedInstanceState) {
4146
super.onCreate(savedInstanceState);
4247
setContentView(R.layout.passcode_lockscreen);
48+
49+
passCodeTextView= (TextView) findViewById(R.id.passcode_label);
50+
51+
checkOldPassCode = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
52+
.getBoolean(UxArgument.ENABLED_PASSCODE, false);
53+
54+
if (checkOldPassCode) {
55+
passCodeTextView.setText("Enter your old passcode");
56+
}
4357
}
4458

4559
@Override
4660
public void onPasscodeEntered(String pass) {
61+
String passCode = PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
62+
.getString(UxArgument.PASSCODE, "");
63+
64+
if (checkOldPassCode) {
65+
if (pass.equals(passCode)) {
66+
checkOldPassCode = false;
67+
passCodeTextView.setText("Enter your new passcode");
68+
} else {
69+
Toast.makeText(this, R.string.toast_wrong_passcode, Toast.LENGTH_SHORT).show();
70+
}
71+
return;
72+
}
73+
4774
if (reenter) {
4875
if (passcode.equals(pass)) {
4976
setResult(RESULT_OK, new Intent().putExtra(UxArgument.PASSCODE, pass));
@@ -58,4 +85,5 @@ public void onPasscodeEntered(String pass) {
5885
Toast.makeText(this, R.string.toast_confirm_passcode, Toast.LENGTH_SHORT).show();
5986
}
6087
}
88+
6189
}

app/src/main/java/org/gnucash/android/ui/settings/PasscodePreferenceFragment.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public class PasscodePreferenceFragment extends PreferenceFragment {
5151
* Request code for disabling passcode
5252
*/
5353
public static final int REQUEST_DISABLE_PASSCODE = 3;
54+
/**
55+
* Request code for changing passcode
56+
*/
57+
public static final int REQUEST_CHANGE_PASSCODE = 4;
5458

5559
private SharedPreferences.Editor editor;
5660
private CheckBoxPreference checkBoxPreference;
@@ -87,16 +91,16 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
8791
passIntent.putExtra(UxArgument.DISABLE_PASSCODE, UxArgument.DISABLE_PASSCODE);
8892
startActivityForResult(passIntent, REQUEST_DISABLE_PASSCODE);
8993
}
90-
editor.putBoolean(UxArgument.ENABLED_PASSCODE, (Boolean) newValue);
91-
editor.commit();
94+
// editor.putBoolean(UxArgument.ENABLED_PASSCODE, (Boolean) newValue);
95+
// editor.commit();
9296
return true;
9397
}
9498
});
9599
findPreference(getString(R.string.key_change_passcode))
96100
.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
97101
@Override
98102
public boolean onPreferenceClick(Preference preference) {
99-
startActivityForResult(intent, PASSCODE_REQUEST_CODE);
103+
startActivityForResult(intent, REQUEST_CHANGE_PASSCODE);
100104
return true;
101105
}
102106
});
@@ -125,6 +129,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
125129
editor.putBoolean(UxArgument.ENABLED_PASSCODE, flag);
126130
checkBoxPreference.setChecked(flag);
127131
break;
132+
case REQUEST_CHANGE_PASSCODE:
133+
if (resultCode == Activity.RESULT_OK && data != null) {
134+
editor.putString(UxArgument.PASSCODE, data.getStringExtra(UxArgument.PASSCODE));
135+
editor.putBoolean(UxArgument.ENABLED_PASSCODE, true);
136+
Toast.makeText(getActivity(), R.string.toast_passcode_set, Toast.LENGTH_SHORT).show();
137+
checkBoxPreference.setTitle(getString(R.string.title_passcode_enabled));
138+
}
139+
break;
128140
}
129141
editor.commit();
130142
}

0 commit comments

Comments
 (0)