From 61434b7b749eb4ecd89cbc9bd882f481d3b3fdbd Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 2 Nov 2011 17:15:03 -0700 Subject: [PATCH] Cleaned up code, better random password generation --- .../astrid/actfm/ActFmLoginActivity.java | 19 +++++++++++++++++++ .../astrid/gtasks/api/MoveListRequest.java | 1 + .../astrid/gtasks/api/UpdateRequest.java | 2 +- .../astrid/service/abtesting/ABOptions.java | 10 ---------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java index 731624e1c..7386f05cf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/ActFmLoginActivity.java @@ -301,13 +301,32 @@ public class ActFmLoginActivity extends Activity implements AuthListener { private String generateRandomPassword() { String acceptable = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*(),."; //$NON-NLS-1$ char[] chars = new char[8]; + char last = 'a'; for (int i = 0; i < chars.length; i++) { char r = acceptable.charAt(rand.nextInt(acceptable.length())); + while (checkSimilar(last, r)) + r = acceptable.charAt(rand.nextInt(acceptable.length())); + last = r; chars[i] = r; } return new String(chars); } + @SuppressWarnings("nls") + private boolean checkSimilar(char last, char check) { + String iSimilar = "ijl1!"; + String oSimilar = "oO0"; + String puncSimilar = ".,"; + + boolean match = (iSimilar.indexOf(last) > 0 && iSimilar.indexOf(check) > 0) + || (oSimilar.indexOf(last) > 0 && oSimilar.indexOf(check) > 0) + || (puncSimilar.indexOf(last) > 0 && puncSimilar.indexOf(check) > 0); + + if (match) + return false; + return true; + } + private EditText addEditField(LinearLayout body, int hint) { TextView label = new TextView(ActFmLoginActivity.this); label.setText(hint); diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java index 67ca106e7..d2a00174b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/MoveListRequest.java @@ -32,6 +32,7 @@ public class MoveListRequest extends PushRequest { @Override protected void recover() { //If there's a good way to recover, put it here + //Since MoveListRequest isn't actually used at the moment, it's probably fine for now } private void transferProperties(Task local) { diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java index 5bbe95c48..5ee27f300 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/UpdateRequest.java @@ -22,7 +22,7 @@ public class UpdateRequest extends PushRequest { @Override protected void recover() { - //If there's a good way to recover, put it here + //Figure out a good way to recover! } } diff --git a/astrid/src/com/todoroo/astrid/service/abtesting/ABOptions.java b/astrid/src/com/todoroo/astrid/service/abtesting/ABOptions.java index 683d152e7..b037f6215 100644 --- a/astrid/src/com/todoroo/astrid/service/abtesting/ABOptions.java +++ b/astrid/src/com/todoroo/astrid/service/abtesting/ABOptions.java @@ -169,14 +169,4 @@ public class ABOptions { //Calls to addOption go here } -// Declare AB options like this: -// public static final String AB_OPTION_FIRST_ACTIVITY = "ab_first_activity"; -// private static final int[] AB_OPTION_FIRST_ACTIVITY_PROBS = { 9, 1 }; -// private static final String[] AB_OPTION_FIRST_ACTIVITY_DESCRIPTIONS = { "ab-show-tasks-first", "ab-show-lists-first" }; -// private static final String[] AB_OPTION_FIRST_ACTIVITY_RELEVANT_EVENTS = { StatisticsConstants.CREATE_TASK, -// StatisticsConstants.TASK_CREATED_TASKLIST, -// StatisticsConstants.USER_FIRST_TASK, -// StatisticsConstants.ACTFM_LIST_SHARED, -// StatisticsConstants.ACTFM_NEW_USER };//*/ - }