From 401a794de9ca328000999a956211b999ed245a10 Mon Sep 17 00:00:00 2001 From: pinae Date: Tue, 13 Oct 2015 12:18:18 +0200 Subject: [PATCH] Creating templates with forced characters only if a setting with template was loaded. --- .../java/de/pinyto/ctSESAM/PasswordSetting.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/pinyto/ctSESAM/PasswordSetting.java b/app/src/main/java/de/pinyto/ctSESAM/PasswordSetting.java index b5021d4..b6ee5b2 100644 --- a/app/src/main/java/de/pinyto/ctSESAM/PasswordSetting.java +++ b/app/src/main/java/de/pinyto/ctSESAM/PasswordSetting.java @@ -38,6 +38,7 @@ public class PasswordSetting { private String notes; private String url; private String template; + private boolean forceCharacterClasses = false; private boolean synced = false; PasswordSetting(String domain) { @@ -543,16 +544,16 @@ private void calculateTemplate() { boolean nInserted = false; boolean oInserted = false; for (int i = 0; i < this.getLength(); i++) { - if (this.useLowerCase() && !aInserted) { + if (this.forceCharacterClasses && this.useLowerCase() && !aInserted) { this.template = this.template + "a"; aInserted = true; - } else if (this.useUpperCase() && !AInserted) { + } else if (this.forceCharacterClasses && this.useUpperCase() && !AInserted) { this.template = this.template + "A"; AInserted = true; - } else if (this.useDigits() && !nInserted) { + } else if (this.forceCharacterClasses && this.useDigits() && !nInserted) { this.template = this.template + "n"; nInserted = true; - } else if (this.useExtra() && !oInserted) { + } else if (this.forceCharacterClasses && this.useExtra() && !oInserted) { this.template = this.template + "o"; oInserted = true; } else { @@ -572,6 +573,7 @@ public String getTemplate() { public void setFullTemplate(String fullTemplate) { Matcher matcher = Pattern.compile("([0123456]);([aAnox]+)").matcher(fullTemplate); if (matcher.matches() && matcher.groupCount() >= 2) { + this.forceCharacterClasses = true; int complexity = Integer.parseInt(matcher.group(1)); switch (complexity) { case 0: @@ -652,7 +654,9 @@ public JSONObject toJSON() { domainObject.put("mDate", this.getModificationDate()); domainObject.put("usedCharacters", this.getCharacterSetAsString()); domainObject.put("extras", this.getExtraCharacterSetAsString()); - domainObject.put("passwordTemplate", this.getFullTemplate()); + if (this.forceCharacterClasses) { + domainObject.put("passwordTemplate", this.getFullTemplate()); + } } catch (JSONException e) { System.out.println("Settings packing error: Unable to pack the JSON data."); }