parent
d52d1cb0a1
commit
57ab645314
3 changed files with 73 additions and 49 deletions
|
@ -523,4 +523,14 @@ public class Entry {
|
|||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public static boolean validateSecret(String secret) {
|
||||
try {
|
||||
new Base32().decode(secret.toUpperCase());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,55 +194,7 @@ public class ManualEntryDialog {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(callingActivity);
|
||||
builder.setTitle(R.string.dialog_title_manual_entry)
|
||||
.setView(inputView)
|
||||
.setPositiveButton(R.string.button_save, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
Entry.OTPType type = (Entry.OTPType) typeInput.getSelectedItem();
|
||||
TokenCalculator.HashAlgorithm algorithm = (TokenCalculator.HashAlgorithm) algorithmInput.getSelectedItem();
|
||||
|
||||
String issuer = issuerInput.getText().toString();
|
||||
String label = labelInput.getText().toString();
|
||||
//Replace spaces with empty characters
|
||||
String secret = secretInput.getText().toString().replaceAll("\\s+","");
|
||||
int digits = Integer.parseInt(digitsInput.getText().toString());
|
||||
|
||||
if (type == Entry.OTPType.TOTP || type == Entry.OTPType.STEAM) {
|
||||
int period = Integer.parseInt(periodInput.getText().toString());
|
||||
|
||||
if (oldEntry == null) {
|
||||
Entry e = new Entry(type, secret, period, digits, issuer, label, algorithm, tagsAdapter.getActiveTags());
|
||||
e.updateOTP();
|
||||
e.setLastUsed(System.currentTimeMillis());
|
||||
|
||||
adapter.addEntry(e);
|
||||
} else {
|
||||
oldEntry.setIssuer(issuer);
|
||||
oldEntry.setLabel(label);
|
||||
oldEntry.setTags(tagsAdapter.getActiveTags());
|
||||
|
||||
adapter.saveAndRefresh(settings.getAutoBackupEncryptedFullEnabled());
|
||||
}
|
||||
|
||||
callingActivity.refreshTags();
|
||||
} else if (type == Entry.OTPType.HOTP) {
|
||||
long counter = Long.parseLong(counterInput.getText().toString());
|
||||
|
||||
if (oldEntry == null) {
|
||||
Entry e = new Entry(type, secret, counter, digits, issuer, label, algorithm, tagsAdapter.getActiveTags());
|
||||
e.updateOTP();
|
||||
e.setLastUsed(System.currentTimeMillis());
|
||||
|
||||
adapter.addEntry(e);
|
||||
} else {
|
||||
oldEntry.setIssuer(issuer);
|
||||
oldEntry.setLabel(label);
|
||||
oldEntry.setTags(tagsAdapter.getActiveTags());
|
||||
|
||||
adapter.saveAndRefresh(settings.getAutoBackupEncryptedFullEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.setPositiveButton(R.string.button_save, null)
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {}
|
||||
|
@ -252,6 +204,65 @@ public class ManualEntryDialog {
|
|||
dialog.show();
|
||||
|
||||
final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//Replace spaces with empty characters
|
||||
String secret = secretInput.getText().toString().replaceAll("\\s+","");
|
||||
|
||||
if (!Entry.validateSecret(secret)) {
|
||||
secretInput.setError(callingActivity.getString(R.string.error_invalid_secret));
|
||||
return;
|
||||
}
|
||||
|
||||
Entry.OTPType type = (Entry.OTPType) typeInput.getSelectedItem();
|
||||
TokenCalculator.HashAlgorithm algorithm = (TokenCalculator.HashAlgorithm) algorithmInput.getSelectedItem();
|
||||
int digits = Integer.parseInt(digitsInput.getText().toString());
|
||||
|
||||
String issuer = issuerInput.getText().toString();
|
||||
String label = labelInput.getText().toString();
|
||||
|
||||
if (type == Entry.OTPType.TOTP || type == Entry.OTPType.STEAM) {
|
||||
int period = Integer.parseInt(periodInput.getText().toString());
|
||||
|
||||
if (oldEntry == null) {
|
||||
Entry e = new Entry(type, secret, period, digits, issuer, label, algorithm, tagsAdapter.getActiveTags());
|
||||
e.updateOTP();
|
||||
e.setLastUsed(System.currentTimeMillis());
|
||||
|
||||
adapter.addEntry(e);
|
||||
} else {
|
||||
oldEntry.setIssuer(issuer);
|
||||
oldEntry.setLabel(label);
|
||||
oldEntry.setTags(tagsAdapter.getActiveTags());
|
||||
|
||||
adapter.saveAndRefresh(settings.getAutoBackupEncryptedFullEnabled());
|
||||
}
|
||||
|
||||
callingActivity.refreshTags();
|
||||
} else if (type == Entry.OTPType.HOTP) {
|
||||
long counter = Long.parseLong(counterInput.getText().toString());
|
||||
|
||||
if (oldEntry == null) {
|
||||
Entry e = new Entry(type, secret, counter, digits, issuer, label, algorithm, tagsAdapter.getActiveTags());
|
||||
e.updateOTP();
|
||||
e.setLastUsed(System.currentTimeMillis());
|
||||
|
||||
adapter.addEntry(e);
|
||||
} else {
|
||||
oldEntry.setIssuer(issuer);
|
||||
oldEntry.setLabel(label);
|
||||
oldEntry.setTags(tagsAdapter.getActiveTags());
|
||||
|
||||
adapter.saveAndRefresh(settings.getAutoBackupEncryptedFullEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
positiveButton.setEnabled(false);
|
||||
|
||||
TextWatcher watcher = new TextWatcher() {
|
||||
|
|
|
@ -73,6 +73,9 @@
|
|||
<string name="toast_qr_unsuported">QR Code not supported</string>
|
||||
<string name="toast_qr_failed_to_generate">Failed to generate QR Code</string>
|
||||
|
||||
<!-- Errors -->
|
||||
<string name="error_invalid_secret">Invalid secret</string>
|
||||
|
||||
<!-- Dialogs -->
|
||||
<string name="dialog_title_auth">Authenticate</string>
|
||||
<string name="dialog_title_manual_entry">Enter details</string>
|
||||
|
|
Loading…
Reference in a new issue