Revision 72d577fb

View differences:

app/res/values/strings.xml
32 32
    <string name="pass_err_upper">Your passphrase did not contain any uppercase letters</string>
33 33
    <string name="pass_err_lower">Your passphrase did not contain any lowercase letters</string>
34 34
    <string name="pass_err_num">Your passphrase did not contain any numbers</string>
35
    <string name="pass_err">Error during passphrase change!</string>
35 36
    
36 37
    <string name="lock_screen_open">Open</string>
37 38
    <string name="title_activity_lock_screen">NoteCipher Locked</string>
......
59 60
	<string name="use_lines_in_notes_summ">If enabled, empty lines will be displayed on all notes to resemble a notepad</string>
60 61
	<string name="vibrate_when_unlocked">Vibrate when unlocked</string>
61 62
	<string name="vibrate_when_unlocked_summ">If enabled, the device will vibrate every time NoteCipher is unlocked with a passphrase</string>
63
	<string name="change_passphrase">Change Passphrase</string>
62 64
	
63 65
</resources>
app/res/xml/settings.xml
5 5
         		<Preference 
6 6
			        android:key="cacheword_timeout"
7 7
			        android:title="@string/change_timeout_prompt_title" />
8
         		<EditTextPreference
9
		            android:key="encrypted_secrets"
10
		            android:title="@string/change_passphrase"
11
		            android:dialogTitle="@string/change_passphrase" />
8 12
         		<CheckBoxPreference
9 13
			        android:key="use_lines_in_notes"
10 14
			        android:title="@string/use_lines_in_notes"
app/src/info/guardianproject/notepadbot/LockScreenActivity.java
31 31
public class LockScreenActivity extends SherlockActivity implements ICacheWordSubscriber {
32 32
    private static final String TAG = "LockScreenActivity";
33 33

  
34
    private final static int MIN_PASS_LENGTH = 8;
35
    // private final static int MAX_PASS_ATTEMPTS = 3;
36
    // private final static int PASS_RETRY_WAIT_TIMEOUT = 30000;
37

  
38 34
    private EditText mEnterPassphrase;
39 35
    private EditText mNewPassphrase;
40 36
    private EditText mConfirmNewPassphrase;
......
119 115
    }
120 116

  
121 117
    private boolean isPasswordValid() {
122
        return validatePassword(mNewPassphrase.getText().toString().toCharArray());
118
    	boolean valid = NConstants.validatePassword(mNewPassphrase.getText().toString().toCharArray());
119
    	if(!valid)
120
    		mPasswordError = getString(R.string.pass_err_length);
121
        return valid;
123 122
    }
124 123

  
125 124
    private boolean isConfirmationFieldEmpty() {
......
233 232
        });
234 233
    }
235 234

  
236
    private boolean validatePassword(char[] pass)
237
    {
238
        if (pass.length < MIN_PASS_LENGTH) {
239
            // should we support some user string message here?
240
            mPasswordError = getString(R.string.pass_err_length);
241
            return false;
242
        }
243
        return true;
244
    }
245

  
246 235
    public class TwoViewSlider {
247 236

  
248 237
        private boolean firstIsShown = true;
app/src/info/guardianproject/notepadbot/NConstants.java
5 5
	
6 6
	 public static final String TAG = "NoteCipher";
7 7
	 public static final int MAX_STREAM_SIZE = 1000000;
8
	 public static final int MIN_PASS_LENGTH = 8;
9
     // public final static int MAX_PASS_ATTEMPTS = 3;
10
     // public final static int PASS_RETRY_WAIT_TIMEOUT = 30000;
11
	 
12
	 /**
13
	  * Checks if the password is valid based on it's length
14
	  * @param pass
15
	  * @return True if the password is a valid one, false otherwise
16
	  */
17
	 public static final boolean validatePassword(char[] pass) {
18
        if (pass.length < NConstants.MIN_PASS_LENGTH) {
19
            return false;
20
        }
21
        return true;
22
	 }
8 23
}
app/src/info/guardianproject/notepadbot/Settings.java
1 1
package info.guardianproject.notepadbot;
2 2

  
3 3

  
4
import java.io.IOException;
5
import java.security.GeneralSecurityException;
6

  
4 7
import net.simonvt.numberpicker.NumberPicker;
5 8
import info.guardianproject.cacheword.CacheWordActivityHandler;
6 9
import info.guardianproject.cacheword.Constants;
7 10
import info.guardianproject.cacheword.ICacheWordSubscriber;
11
import info.guardianproject.cacheword.PassphraseSecrets;
8 12

  
9 13
import android.annotation.SuppressLint;
10 14
import android.app.AlertDialog;
......
19 23
import android.preference.PreferenceManager;
20 24
import android.support.v4.app.NavUtils;
21 25
import android.util.Log;
26
import android.widget.Toast;
22 27

  
23 28
import com.actionbarsherlock.app.SherlockPreferenceActivity;
24 29
import com.actionbarsherlock.view.MenuItem;
......
50 55
								.setOnPreferenceClickListener(changeLockTimeoutListener);
51 56
							findPreference(Constants.SHARED_PREFS_VIBRATE)
52 57
								.setOnPreferenceChangeListener(vibrateChangeListener);
58
							findPreference(Constants.SHARED_PREFS_SECRETS)
59
								.setOnPreferenceChangeListener(passphraseChangeListener);
60
							
53 61
						}
54 62
					})
55 63
					.commit();
......
60 68
				.setOnPreferenceClickListener(changeLockTimeoutListener);
61 69
			findPreference(Constants.SHARED_PREFS_VIBRATE)
62 70
				.setOnPreferenceChangeListener(vibrateChangeListener);
71
			findPreference(Constants.SHARED_PREFS_SECRETS)
72
				.setOnPreferenceChangeListener(passphraseChangeListener);
63 73
		}
64 74
	}
65 75
	
......
99 109
		}
100 110
	};
101 111
	
112
	private Preference.OnPreferenceChangeListener passphraseChangeListener = 
113
			new OnPreferenceChangeListener(){
114
		@Override
115
		public boolean onPreferenceChange(Preference pref, Object newValue) {
116
			try {
117
				char[] pass = ((String) newValue).toCharArray();
118
				if (NConstants.validatePassword(pass)) {
119
					mCacheWord.changePassphrase((PassphraseSecrets) mCacheWord.getCachedSecrets(), pass);
120
				} else {
121
					Toast.makeText(getApplicationContext(), 
122
							R.string.pass_err_length, Toast.LENGTH_SHORT).show();
123
				}
124
			} catch (IOException e) {
125
				Toast.makeText(getApplicationContext(), 
126
						R.string.pass_err, Toast.LENGTH_SHORT).show();
127
			}
128
			return false;
129
		}
130
	};
131
	
102 132
	public static final boolean getNoteLinesOption(Context context) {
103 133
		boolean defValue = context.getResources().getBoolean(R.bool.notecipher_uselines_default);
104 134
        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(NConstants.SHARED_PREFS_NOTELINES, defValue);
......
175 205
        startActivity(intent);
176 206
        finish();
177 207
    }
178
}
208
}

Also available in: Unified diff