Skip to content
Snippets Groups Projects
Commit 3ddfe44b authored by akwizgran's avatar akwizgran
Browse files

Show feedback during setup if passwords don't match. Dev task #49.

parent bacd8ec0
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
<string name="choose_password">Choose your password:</string> <string name="choose_password">Choose your password:</string>
<string name="confirm_password">Confirm your password:</string> <string name="confirm_password">Confirm your password:</string>
<string name="format_min_password">Password must be at least %1$d characters long</string> <string name="format_min_password">Password must be at least %1$d characters long</string>
<string name="passwords_do_not_match">Passwords do not match</string>
<string name="enter_password">Enter your password:</string> <string name="enter_password">Enter your password:</string>
<string name="try_again">Wrong password, try again:</string> <string name="try_again">Wrong password, try again:</string>
<string name="expiry_warning">This software has expired.\nPlease install a newer version.</string> <string name="expiry_warning">This software has expired.\nPlease install a newer version.</string>
......
...@@ -26,10 +26,12 @@ import org.briarproject.api.crypto.CryptoExecutor; ...@@ -26,10 +26,12 @@ import org.briarproject.api.crypto.CryptoExecutor;
import org.briarproject.api.crypto.KeyPair; import org.briarproject.api.crypto.KeyPair;
import org.briarproject.api.db.DatabaseConfig; import org.briarproject.api.db.DatabaseConfig;
import org.briarproject.util.StringUtils; import org.briarproject.util.StringUtils;
import roboguice.activity.RoboActivity; import roboguice.activity.RoboActivity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.view.View; import android.view.View;
...@@ -48,6 +50,7 @@ public class SetupActivity extends RoboActivity implements OnClickListener { ...@@ -48,6 +50,7 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
@Inject @CryptoExecutor private Executor cryptoExecutor; @Inject @CryptoExecutor private Executor cryptoExecutor;
private EditText nicknameEntry = null; private EditText nicknameEntry = null;
private EditText passwordEntry = null, passwordConfirmation = null; private EditText passwordEntry = null, passwordConfirmation = null;
private TextView feedback = null;
private Button continueButton = null; private Button continueButton = null;
private ProgressBar progress = null; private ProgressBar progress = null;
...@@ -125,13 +128,13 @@ public class SetupActivity extends RoboActivity implements OnClickListener { ...@@ -125,13 +128,13 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
passwordConfirmation.setInputType(inputType); passwordConfirmation.setInputType(inputType);
layout.addView(passwordConfirmation); layout.addView(passwordConfirmation);
TextView minPasswordLength = new TextView(this); feedback = new TextView(this);
minPasswordLength.setGravity(CENTER); feedback.setGravity(CENTER);
minPasswordLength.setTextSize(14); feedback.setTextSize(14);
minPasswordLength.setPadding(10, 10, 10, 10); feedback.setPadding(10, 10, 10, 10);
String format = getResources().getString(R.string.format_min_password); String format = getResources().getString(R.string.format_min_password);
minPasswordLength.setText(String.format(format, MIN_PASSWORD_LENGTH)); feedback.setText(String.format(format, MIN_PASSWORD_LENGTH));
layout.addView(minPasswordLength); layout.addView(feedback);
continueButton = new Button(this); continueButton = new Button(this);
continueButton.setLayoutParams(WRAP_WRAP); continueButton.setLayoutParams(WRAP_WRAP);
...@@ -142,6 +145,7 @@ public class SetupActivity extends RoboActivity implements OnClickListener { ...@@ -142,6 +145,7 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
progress = new ProgressBar(this); progress = new ProgressBar(this);
progress.setLayoutParams(WRAP_WRAP); progress.setLayoutParams(WRAP_WRAP);
progress.setPadding(0, 10, 0, 0);
progress.setIndeterminate(true); progress.setIndeterminate(true);
progress.setVisibility(GONE); progress.setVisibility(GONE);
layout.addView(progress); layout.addView(progress);
...@@ -162,6 +166,15 @@ public class SetupActivity extends RoboActivity implements OnClickListener { ...@@ -162,6 +166,15 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
boolean passwordsMatch = Arrays.equals(firstPassword, secondPassword); boolean passwordsMatch = Arrays.equals(firstPassword, secondPassword);
for(int i = 0; i < firstPassword.length; i++) firstPassword[i] = 0; for(int i = 0; i < firstPassword.length; i++) firstPassword[i] = 0;
for(int i = 0; i < secondPassword.length; i++) secondPassword[i] = 0; for(int i = 0; i < secondPassword.length; i++) secondPassword[i] = 0;
if(!passwordLength) {
Resources res = getResources();
String format = res.getString(R.string.format_min_password);
feedback.setText(String.format(format, MIN_PASSWORD_LENGTH));
} else if(!passwordsMatch) {
feedback.setText(R.string.passwords_do_not_match);
} else {
feedback.setText("");
}
boolean valid = nicknameNotEmpty && passwordLength && passwordsMatch; boolean valid = nicknameNotEmpty && passwordLength && passwordsMatch;
continueButton.setEnabled(valid); continueButton.setEnabled(valid);
} }
...@@ -174,13 +187,15 @@ public class SetupActivity extends RoboActivity implements OnClickListener { ...@@ -174,13 +187,15 @@ public class SetupActivity extends RoboActivity implements OnClickListener {
} }
public void onClick(View view) { public void onClick(View view) {
// Replace the feedback text and button with a progress bar
feedback.setVisibility(GONE);
continueButton.setVisibility(GONE);
progress.setVisibility(VISIBLE);
// Copy the passwords and erase the originals
final String nickname = nicknameEntry.getText().toString(); final String nickname = nicknameEntry.getText().toString();
final char[] password = getChars(passwordEntry.getText()); final char[] password = getChars(passwordEntry.getText());
delete(passwordEntry.getText()); delete(passwordEntry.getText());
delete(passwordConfirmation.getText()); delete(passwordConfirmation.getText());
// Replace the button with a progress bar
continueButton.setVisibility(GONE);
progress.setVisibility(VISIBLE);
// Store the DB key and create the identity in a background thread // Store the DB key and create the identity in a background thread
cryptoExecutor.execute(new Runnable() { cryptoExecutor.execute(new Runnable() {
public void run() { public void run() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment