From 82ae0a8629a42bc169b4b1993bc8257457703e3f Mon Sep 17 00:00:00 2001 From: glowinthedark <48893368+glowinthedark@users.noreply.github.com> Date: Mon, 17 Aug 2020 12:40:03 +0200 Subject: Allow adding digits and symbols in XkPasswd generator using mask-like values (#1023) * - XkPasswordGeneratorDialogFragment: add symbol/number mask to allow appending numbers+symbols via a mask such as `ddds` which would generate random.password123!; position of `d` and `s` is not currently considered; only the count is relevant * - update CHANGELOG.md * - update CHANGELOG.md * - rename constants * Update CHANGELOG.md Co-authored-by: Harsh Shandilya * - add missing marginTop * - add missing marginTop Co-authored-by: null Co-authored-by: Harsh Shandilya Co-authored-by: glowinthedark Co-authored-by: Harsh Shandilya --- .../java/com/zeapo/pwdstore/pwgenxkpwd/CapsType.kt | 2 +- .../zeapo/pwdstore/pwgenxkpwd/PasswordBuilder.kt | 4 ++-- .../dialogs/XkPasswordGeneratorDialogFragment.kt | 12 +++++++++-- app/src/main/res/layout/fragment_xkpwgen.xml | 23 +++++++++++++++++++++- app/src/main/res/values/arrays.xml | 2 +- app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 38 insertions(+), 7 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/CapsType.kt b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/CapsType.kt index a0311b8d..f98a9f10 100644 --- a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/CapsType.kt +++ b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/CapsType.kt @@ -5,5 +5,5 @@ package com.zeapo.pwdstore.pwgenxkpwd enum class CapsType { - lowercase, UPPERCASE, TitleCase, Sentencecase, As_iS + lowercase, UPPERCASE, TitleCase, Sentence, As_iS } diff --git a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/PasswordBuilder.kt b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/PasswordBuilder.kt index 04cd16f6..587a5350 100644 --- a/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/PasswordBuilder.kt +++ b/app/src/main/java/com/zeapo/pwdstore/pwgenxkpwd/PasswordBuilder.kt @@ -22,7 +22,7 @@ class PasswordBuilder(ctx: Context) { private var maxWordLength = 9 private var minWordLength = 5 private var separator = "." - private var capsType = CapsType.Sentencecase + private var capsType = CapsType.Sentence private var prependDigits = 0 private var numDigits = 0 private var isPrependWithSeparator = false @@ -109,7 +109,7 @@ class PasswordBuilder(ctx: Context) { val candidate = wordBank.secureRandomElement() val s = when (capsType) { CapsType.UPPERCASE -> candidate.toUpperCase(Locale.getDefault()) - CapsType.Sentencecase -> if (i == 0) candidate.capitalize(Locale.getDefault()) else candidate + CapsType.Sentence -> if (i == 0) candidate.capitalize(Locale.getDefault()) else candidate CapsType.TitleCase -> candidate.capitalize(Locale.getDefault()) CapsType.lowercase -> candidate.toLowerCase(Locale.getDefault()) CapsType.As_iS -> candidate diff --git a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/XkPasswordGeneratorDialogFragment.kt b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/XkPasswordGeneratorDialogFragment.kt index ebd014c5..527e4c6c 100644 --- a/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/XkPasswordGeneratorDialogFragment.kt +++ b/app/src/main/java/com/zeapo/pwdstore/ui/dialogs/XkPasswordGeneratorDialogFragment.kt @@ -58,6 +58,7 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() { binding.xkNumWords.setText(prefs.getString(PREF_KEY_NUM_WORDS, DEFAULT_NUMBER_OF_WORDS)) binding.xkSeparator.setText(prefs.getString(PREF_KEY_SEPARATOR, DEFAULT_WORD_SEPARATOR)) + binding.xkNumberSymbolMask.setText(prefs.getString(PREF_KEY_EXTRA_SYMBOLS_MASK, DEFAULT_EXTRA_SYMBOLS_MASK)) binding.xkPasswordText.typeface = monoTypeface @@ -92,6 +93,8 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() { .setMinimumWordLength(DEFAULT_MIN_WORD_LENGTH) .setMaximumWordLength(DEFAULT_MAX_WORD_LENGTH) .setSeparator(binding.xkSeparator.text.toString()) + .appendNumbers(binding.xkNumberSymbolMask.text!!.count { c -> c == EXTRA_CHAR_PLACEHOLDER_DIGIT }) + .appendSymbols(binding.xkNumberSymbolMask.text!!.count { c -> c == EXTRA_CHAR_PLACEHOLDER_SYMBOL }) .setCapitalization(CapsType.valueOf(binding.xkCapType.selectedItem.toString())).create() } catch (e: PasswordGenerator.PasswordGeneratorException) { Toast.makeText(requireActivity(), e.message, Toast.LENGTH_SHORT).show() @@ -105,6 +108,7 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() { putString(PREF_KEY_CAPITALS_STYLE, binding.xkCapType.selectedItem.toString()) putString(PREF_KEY_NUM_WORDS, binding.xkNumWords.text.toString()) putString(PREF_KEY_SEPARATOR, binding.xkSeparator.text.toString()) + putString(PREF_KEY_EXTRA_SYMBOLS_MASK, binding.xkNumberSymbolMask.text.toString()) } } @@ -113,12 +117,16 @@ class XkPasswordGeneratorDialogFragment : DialogFragment() { const val PREF_KEY_CAPITALS_STYLE = "pref_key_capitals_style" const val PREF_KEY_NUM_WORDS = "pref_key_num_words" const val PREF_KEY_SEPARATOR = "pref_key_separator" - val DEFAULT_CAPS_STYLE = CapsType.Sentencecase.name - val DEFAULT_CAPS_INDEX = CapsType.Sentencecase.ordinal + const val PREF_KEY_EXTRA_SYMBOLS_MASK = "pref_key_xkpwgen_extra_symbols_mask" + val DEFAULT_CAPS_STYLE = CapsType.Sentence.name + val DEFAULT_CAPS_INDEX = CapsType.Sentence.ordinal const val DEFAULT_NUMBER_OF_WORDS = "3" const val DEFAULT_WORD_SEPARATOR = "." + const val DEFAULT_EXTRA_SYMBOLS_MASK = "ds" const val DEFAULT_MIN_WORD_LENGTH = 3 const val DEFAULT_MAX_WORD_LENGTH = 9 const val FALLBACK_ERROR_PASS = "42" + const val EXTRA_CHAR_PLACEHOLDER_DIGIT = 'd' + const val EXTRA_CHAR_PLACEHOLDER_SYMBOL = 's' } } diff --git a/app/src/main/res/layout/fragment_xkpwgen.xml b/app/src/main/res/layout/fragment_xkpwgen.xml index 112c94d9..749fba47 100644 --- a/app/src/main/res/layout/fragment_xkpwgen.xml +++ b/app/src/main/res/layout/fragment_xkpwgen.xml @@ -75,7 +75,28 @@ android:entries="@array/capitalization_type_values" android:entryValues="@array/capitalization_type_values" android:spinnerMode="dropdown" + app:layout_constraintEnd_toEndOf="@id/total_words" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@id/separator" /> + app:layout_constraintTop_toBottomOf="@id/total_words" /> + + + + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1ccdd5eb..6b5edf6c 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -18,7 +18,7 @@ lowercase UPPERCASE TitleCase - Sentencecase + Sentence Classic diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4b1e81bf..fe2a3488 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -390,4 +390,6 @@ A file by that name already exists A folder by that name already exists + Digits/Symbols (d/s) + ds -- cgit v1.2.3