mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Password characters in settings
This commit is contained in:
@@ -30,14 +30,16 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.keepassdroid.password.PasswordGenerator;
|
||||
import com.keepassdroid.settings.PrefsUtil;
|
||||
import com.kunzisoft.keepass.R;
|
||||
import com.keepassdroid.password.PasswordGenerator;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class GeneratePasswordFragment extends DialogFragment {
|
||||
|
||||
@@ -47,6 +49,15 @@ public class GeneratePasswordFragment extends DialogFragment {
|
||||
private View root;
|
||||
private EditText lengthTextView;
|
||||
|
||||
private CompoundButton uppercaseBox;
|
||||
private CompoundButton lowercaseBox;
|
||||
private CompoundButton digitsBox;
|
||||
private CompoundButton minusBox;
|
||||
private CompoundButton underlineBox;
|
||||
private CompoundButton spaceBox;
|
||||
private CompoundButton specialsBox;
|
||||
private CompoundButton bracketsBox;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -67,6 +78,17 @@ public class GeneratePasswordFragment extends DialogFragment {
|
||||
|
||||
lengthTextView = (EditText) root.findViewById(R.id.length);
|
||||
|
||||
uppercaseBox = (CompoundButton) root.findViewById(R.id.cb_uppercase);
|
||||
lowercaseBox = (CompoundButton) root.findViewById(R.id.cb_lowercase);
|
||||
digitsBox = (CompoundButton) root.findViewById(R.id.cb_digits);
|
||||
minusBox = (CompoundButton) root.findViewById(R.id.cb_minus);
|
||||
underlineBox = (CompoundButton) root.findViewById(R.id.cb_underline);
|
||||
spaceBox = (CompoundButton) root.findViewById(R.id.cb_space);
|
||||
specialsBox = (CompoundButton) root.findViewById(R.id.cb_specials);
|
||||
bracketsBox = (CompoundButton) root.findViewById(R.id.cb_brackets);
|
||||
|
||||
assignDefaultCharacters();
|
||||
|
||||
SeekBar seekBar = (SeekBar) root.findViewById(R.id.seekbar_length);
|
||||
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
@@ -116,6 +138,46 @@ public class GeneratePasswordFragment extends DialogFragment {
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
private void assignDefaultCharacters() {
|
||||
uppercaseBox.setChecked(false);
|
||||
lowercaseBox.setChecked(false);
|
||||
digitsBox.setChecked(false);
|
||||
minusBox.setChecked(false);
|
||||
underlineBox.setChecked(false);
|
||||
spaceBox.setChecked(false);
|
||||
specialsBox.setChecked(false);
|
||||
bracketsBox.setChecked(false);
|
||||
|
||||
Set<String> defaultPasswordChars =
|
||||
PrefsUtil.getDefaultPasswordCharacters(getContext().getApplicationContext());
|
||||
for(String passwordChar : defaultPasswordChars) {
|
||||
if (passwordChar.equals(getString(R.string.value_password_uppercase))) {
|
||||
uppercaseBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_lowercase))) {
|
||||
lowercaseBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_digits))) {
|
||||
digitsBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_minus))) {
|
||||
minusBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_underline))) {
|
||||
underlineBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_space))) {
|
||||
spaceBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_special))) {
|
||||
specialsBox.setChecked(true);
|
||||
}
|
||||
else if (passwordChar.equals(getString(R.string.value_password_brackets))) {
|
||||
bracketsBox.setChecked(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fillPassword() {
|
||||
EditText txtPassword = (EditText) root.findViewById(R.id.password);
|
||||
txtPassword.setText(generatePassword());
|
||||
@@ -123,23 +185,19 @@ public class GeneratePasswordFragment extends DialogFragment {
|
||||
|
||||
public String generatePassword() {
|
||||
String password = "";
|
||||
|
||||
try {
|
||||
int length = Integer.valueOf(((EditText) root.findViewById(R.id.length)).getText().toString());
|
||||
|
||||
((CheckBox) root.findViewById(R.id.cb_uppercase)).isChecked();
|
||||
|
||||
PasswordGenerator generator = new PasswordGenerator(getActivity());
|
||||
|
||||
password = generator.generatePassword(length,
|
||||
((CheckBox) root.findViewById(R.id.cb_uppercase)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_lowercase)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_digits)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_minus)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_underline)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_space)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_specials)).isChecked(),
|
||||
((CheckBox) root.findViewById(R.id.cb_brackets)).isChecked());
|
||||
uppercaseBox.isChecked(),
|
||||
lowercaseBox.isChecked(),
|
||||
digitsBox.isChecked(),
|
||||
minusBox.isChecked(),
|
||||
underlineBox.isChecked(),
|
||||
spaceBox.isChecked(),
|
||||
specialsBox.isChecked(),
|
||||
bracketsBox.isChecked());
|
||||
} catch (NumberFormatException e) {
|
||||
Toast.makeText(getContext(), R.string.error_wrong_length, Toast.LENGTH_LONG).show();
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -25,6 +25,10 @@ import android.preference.PreferenceManager;
|
||||
|
||||
import com.kunzisoft.keepass.R;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class PrefsUtil {
|
||||
|
||||
public static float getListTextSize(Context ctx) {
|
||||
@@ -37,4 +41,12 @@ public class PrefsUtil {
|
||||
return prefs.getInt(ctx.getString(R.string.password_length_key),
|
||||
Integer.parseInt(ctx.getString(R.string.default_password_length)));
|
||||
}
|
||||
|
||||
public static Set<String> getDefaultPasswordCharacters(Context ctx) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
||||
return prefs.getStringSet(ctx.getString(R.string.list_password_generator_options_key),
|
||||
new HashSet<>(Arrays.asList(
|
||||
ctx.getResources()
|
||||
.getStringArray(R.array.list_password_generator_options_default_values))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/RelativeLayout"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
||||
@@ -202,8 +202,10 @@
|
||||
<string name="history">Historique</string>
|
||||
<string name="appearance">Apparence</string>
|
||||
<string name="general">Générale</string>
|
||||
<string name="password_size_title">Taille des mots de passe</string>
|
||||
<string name="password_size_summary">Déterminer la taille par défaut des mots de passe lors de leurs générations</string>
|
||||
<string name="password_size_title">Taille de mot de passe</string>
|
||||
<string name="password_size_summary">Définir la taille par défaut du mot de passe généré</string>
|
||||
<string name="list_password_generator_options_title">Caractères de mot de passe</string>
|
||||
<string name="list_password_generator_options_summary">Définir les caractères par défaut du générateur de mot de passe</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 secondes</item>
|
||||
|
||||
@@ -67,16 +67,53 @@
|
||||
<item translatable="false">300000</item>
|
||||
<item translatable="false">-1</item>
|
||||
</string-array>
|
||||
|
||||
<string name="list_size_default" translatable="false">18</string>
|
||||
<string-array name="list_size_values">
|
||||
<item translatable="false">14</item>
|
||||
<item translatable="false">18</item>
|
||||
<item translatable="false">26</item>
|
||||
</string-array>
|
||||
|
||||
<string name="list_style_name_light" translatable="false">KeepassDXStyle_Light</string>
|
||||
<string name="list_style_name_night" translatable="false">KeepassDXStyle_Night</string>
|
||||
<string-array name="list_style_values">
|
||||
<item translatable="false">@string/list_style_name_light</item>
|
||||
<item translatable="false">@string/list_style_name_night</item>
|
||||
</string-array>
|
||||
|
||||
<string name="list_password_generator_options_key" translatable="false">list_password_generator_options_key</string>
|
||||
<string name="value_password_uppercase" translatable="false">value_password_uppercase</string>
|
||||
<string name="value_password_lowercase" translatable="false">value_password_lowercase</string>
|
||||
<string name="value_password_digits" translatable="false">value_password_digits</string>
|
||||
<string name="value_password_minus" translatable="false">value_password_minus</string>
|
||||
<string name="value_password_underline" translatable="false">value_password_underline</string>
|
||||
<string name="value_password_space" translatable="false">value_password_space</string>
|
||||
<string name="value_password_special" translatable="false">value_password_special</string>
|
||||
<string name="value_password_brackets" translatable="false">value_password_brackets</string>
|
||||
<string-array name="list_password_generator_options_default_values">
|
||||
<item translatable="false">@string/value_password_uppercase</item>
|
||||
<item translatable="false">@string/value_password_lowercase</item>
|
||||
<item translatable="false">@string/value_password_digits</item>
|
||||
</string-array>
|
||||
<string-array name="list_password_generator_options_values">
|
||||
<item translatable="false">@string/value_password_uppercase</item>
|
||||
<item translatable="false">@string/value_password_lowercase</item>
|
||||
<item translatable="false">@string/value_password_digits</item>
|
||||
<item translatable="false">@string/value_password_minus</item>
|
||||
<item translatable="false">@string/value_password_underline</item>
|
||||
<item translatable="false">@string/value_password_space</item>
|
||||
<item translatable="false">@string/value_password_special</item>
|
||||
<item translatable="false">@string/value_password_brackets</item>
|
||||
</string-array>
|
||||
<string-array name="list_password_generator_options_entries">
|
||||
<item translatable="false">@string/uppercase</item>
|
||||
<item translatable="false">@string/lowercase</item>
|
||||
<item translatable="false">@string/digits</item>
|
||||
<item translatable="false">@string/minus</item>
|
||||
<item translatable="false">@string/underline</item>
|
||||
<item translatable="false">@string/space</item>
|
||||
<item translatable="false">@string/special</item>
|
||||
<item translatable="false">@string/brackets</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -202,8 +202,10 @@
|
||||
<string name="history">History</string>
|
||||
<string name="appearance">Appearance</string>
|
||||
<string name="general">General</string>
|
||||
<string name="password_size_title">Passwords size</string>
|
||||
<string name="password_size_summary">Set the default size of passwords during their generations</string>
|
||||
<string name="password_size_title">Password size</string>
|
||||
<string name="password_size_summary">Set the default size of the generated password</string>
|
||||
<string name="list_password_generator_options_title">Password characters</string>
|
||||
<string name="list_password_generator_options_summary">Set the default password generator characters</string>
|
||||
|
||||
<string-array name="clipboard_timeout_options">
|
||||
<item>30 seconds</item>
|
||||
|
||||
@@ -63,6 +63,14 @@
|
||||
app:min="@string/min_password_length"
|
||||
android:max="@string/max_password_length" />
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:key="@string/list_password_generator_options_key"
|
||||
android:title="@string/list_password_generator_options_title"
|
||||
android:summary="@string/list_password_generator_options_summary"
|
||||
android:entries="@array/list_password_generator_options_entries"
|
||||
android:entryValues="@array/list_password_generator_options_values"
|
||||
android:defaultValue="@array/list_password_generator_options_default_values"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="@string/maskpass_key"
|
||||
android:title="@string/maskpass_title"
|
||||
|
||||
Reference in New Issue
Block a user