Skip to content

Commit e76e9d4

Browse files
salevajoStephan Heffnerdroidmonkey
authored
Passphrase "MIXED case" Type (#11255)
* An additional approach to create passphrases with one random word being in UPPERCASE. * Also remove duplicate character count from passphrase generator --------- Co-authored-by: Stephan Heffner <[email protected]> Co-authored-by: Jonathan White <[email protected]>
1 parent 9670a5e commit e76e9d4

File tree

6 files changed

+78
-90
lines changed

6 files changed

+78
-90
lines changed

share/translations/keepassxc_en.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6902,10 +6902,6 @@ The following data is missing:
69026902
<source>Word Count:</source>
69036903
<translation type="unfinished"></translation>
69046904
</message>
6905-
<message>
6906-
<source>Character Count:</source>
6907-
<translation type="unfinished"></translation>
6908-
</message>
69096905
<message>
69106906
<source>Word Case:</source>
69116907
<translation type="unfinished"></translation>
@@ -6918,10 +6914,6 @@ The following data is missing:
69186914
<source>Add custom wordlist</source>
69196915
<translation type="unfinished"></translation>
69206916
</message>
6921-
<message>
6922-
<source>character</source>
6923-
<translation type="unfinished"></translation>
6924-
</message>
69256917
<message>
69266918
<source>Close</source>
69276919
<translation type="unfinished"></translation>
@@ -7035,6 +7027,10 @@ Do you want to overwrite it?</source>
70357027
<source>Characters: %1</source>
70367028
<translation type="unfinished"></translation>
70377029
</message>
7030+
<message>
7031+
<source>MIXED case</source>
7032+
<translation type="unfinished"></translation>
7033+
</message>
70387034
<message>
70397035
<source>Excluded characters: &quot;0&quot;, &quot;1&quot;, &quot;l&quot;, &quot;I&quot;, &quot;O&quot;, &quot;|&quot;, &quot;&quot;, &quot;B&quot;, &quot;8&quot;, &quot;G&quot;, &quot;6&quot;</source>
70407036
<translation type="unfinished"></translation>

src/core/PassphraseGenerator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ QString PassphraseGenerator::generatePassphrase() const
122122
}
123123

124124
QStringList words;
125+
int randomIndex = randomGen()->randomUInt(static_cast<quint32>(m_wordCount));
125126
for (int i = 0; i < m_wordCount; ++i) {
126127
int wordIndex = randomGen()->randomUInt(static_cast<quint32>(m_wordlist.size()));
127128
auto tmpWord = m_wordlist.at(wordIndex);
@@ -134,6 +135,9 @@ QString PassphraseGenerator::generatePassphrase() const
134135
case TITLECASE:
135136
tmpWord = tmpWord.replace(0, 1, tmpWord.left(1).toUpper());
136137
break;
138+
case MIXEDCASE:
139+
tmpWord = i == randomIndex ? tmpWord.toUpper() : tmpWord.toLower();
140+
break;
137141
case LOWERCASE:
138142
tmpWord = tmpWord.toLower();
139143
break;

src/core/PassphraseGenerator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class PassphraseGenerator
3030
{
3131
LOWERCASE,
3232
UPPERCASE,
33-
TITLECASE
33+
TITLECASE,
34+
MIXEDCASE
3435
};
3536

3637
double estimateEntropy(int wordCount = 0);

src/gui/PasswordGeneratorWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
9999
m_ui->wordCaseComboBox->addItem(tr("lower case"), PassphraseGenerator::LOWERCASE);
100100
m_ui->wordCaseComboBox->addItem(tr("UPPER CASE"), PassphraseGenerator::UPPERCASE);
101101
m_ui->wordCaseComboBox->addItem(tr("Title Case"), PassphraseGenerator::TITLECASE);
102+
m_ui->wordCaseComboBox->addItem(tr("MIXED case"), PassphraseGenerator::MIXEDCASE);
102103

103104
// load system-wide wordlists
104105
QDir path(resources()->wordlistPath(""));
@@ -276,7 +277,6 @@ void PasswordGeneratorWidget::updatePasswordStrength()
276277
PasswordHealth passwordHealth(0);
277278
if (m_ui->tabWidget->currentIndex() == Diceware) {
278279
passwordHealth.init(m_dicewareGenerator->estimateEntropy());
279-
m_ui->charactersInPassphraseLabel->setText(QString::number(m_ui->editNewPassword->text().length()));
280280
} else {
281281
passwordHealth = PasswordHealth(m_ui->editNewPassword->text());
282282
}

src/gui/PasswordGeneratorWidget.ui

Lines changed: 64 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -769,26 +769,6 @@ QProgressBar::chunk {
769769
<layout class="QGridLayout" name="gridLayout_2">
770770
<item row="0" column="0">
771771
<layout class="QGridLayout" name="gridLayout_3">
772-
<item row="2" column="1" alignment="Qt::AlignRight">
773-
<widget class="QLabel" name="labelWordSeparator">
774-
<property name="text">
775-
<string>Word Separator:</string>
776-
</property>
777-
</widget>
778-
</item>
779-
<item row="0" column="1" alignment="Qt::AlignRight">
780-
<widget class="QLabel" name="labelWordList">
781-
<property name="sizePolicy">
782-
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
783-
<horstretch>0</horstretch>
784-
<verstretch>0</verstretch>
785-
</sizepolicy>
786-
</property>
787-
<property name="text">
788-
<string>Wordlist:</string>
789-
</property>
790-
</widget>
791-
</item>
792772
<item row="1" column="2">
793773
<layout class="QHBoxLayout" name="horizontalLayout_3">
794774
<property name="sizeConstraint">
@@ -834,29 +814,59 @@ QProgressBar::chunk {
834814
</item>
835815
</layout>
836816
</item>
837-
<item row="1" column="1" alignment="Qt::AlignRight">
838-
<widget class="QLabel" name="labelWordCount">
817+
<item row="3" column="1" alignment="Qt::AlignRight">
818+
<widget class="QLabel" name="wordCaseLabel">
839819
<property name="text">
840-
<string>Word Count:</string>
841-
</property>
842-
<property name="buddy">
843-
<cstring>spinBoxLength</cstring>
820+
<string>Word Case:</string>
844821
</property>
845822
</widget>
846823
</item>
847-
<item row="4" column="1" alignment="Qt::AlignRight">
848-
<widget class="QLabel" name="characterCountLabel">
824+
<item row="2" column="1" alignment="Qt::AlignRight">
825+
<widget class="QLabel" name="labelWordSeparator">
849826
<property name="text">
850-
<string>Character Count:</string>
827+
<string>Word Separator:</string>
851828
</property>
852829
</widget>
853830
</item>
854-
<item row="3" column="1" alignment="Qt::AlignRight">
855-
<widget class="QLabel" name="wordCaseLabel">
856-
<property name="text">
857-
<string>Word Case:</string>
858-
</property>
859-
</widget>
831+
<item row="0" column="2">
832+
<layout class="QHBoxLayout" name="horizontalLayout_10">
833+
<item>
834+
<widget class="QComboBox" name="comboBoxWordList">
835+
<property name="sizePolicy">
836+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
837+
<horstretch>0</horstretch>
838+
<verstretch>0</verstretch>
839+
</sizepolicy>
840+
</property>
841+
</widget>
842+
</item>
843+
<item>
844+
<widget class="QPushButton" name="buttonDeleteWordList">
845+
<property name="focusPolicy">
846+
<enum>Qt::TabFocus</enum>
847+
</property>
848+
<property name="toolTip">
849+
<string>Delete selected wordlist</string>
850+
</property>
851+
<property name="accessibleDescription">
852+
<string>Delete selected wordlist</string>
853+
</property>
854+
</widget>
855+
</item>
856+
<item>
857+
<widget class="QPushButton" name="buttonAddWordList">
858+
<property name="focusPolicy">
859+
<enum>Qt::TabFocus</enum>
860+
</property>
861+
<property name="toolTip">
862+
<string>Add custom wordlist</string>
863+
</property>
864+
<property name="accessibleDescription">
865+
<string>Add custom wordlist</string>
866+
</property>
867+
</widget>
868+
</item>
869+
</layout>
860870
</item>
861871
<item row="3" column="2">
862872
<layout class="QHBoxLayout" name="horizontalLayout_6">
@@ -878,6 +888,16 @@ QProgressBar::chunk {
878888
</item>
879889
</layout>
880890
</item>
891+
<item row="1" column="1" alignment="Qt::AlignRight">
892+
<widget class="QLabel" name="labelWordCount">
893+
<property name="text">
894+
<string>Word Count:</string>
895+
</property>
896+
<property name="buddy">
897+
<cstring>spinBoxLength</cstring>
898+
</property>
899+
</widget>
900+
</item>
881901
<item row="2" column="2">
882902
<layout class="QHBoxLayout" name="horizontalLayout_9">
883903
<item>
@@ -914,50 +934,16 @@ QProgressBar::chunk {
914934
</item>
915935
</layout>
916936
</item>
917-
<item row="0" column="2">
918-
<layout class="QHBoxLayout" name="horizontalLayout_10">
919-
<item>
920-
<widget class="QComboBox" name="comboBoxWordList">
921-
<property name="sizePolicy">
922-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
923-
<horstretch>0</horstretch>
924-
<verstretch>0</verstretch>
925-
</sizepolicy>
926-
</property>
927-
</widget>
928-
</item>
929-
<item>
930-
<widget class="QPushButton" name="buttonDeleteWordList">
931-
<property name="focusPolicy">
932-
<enum>Qt::TabFocus</enum>
933-
</property>
934-
<property name="toolTip">
935-
<string>Delete selected wordlist</string>
936-
</property>
937-
<property name="accessibleDescription">
938-
<string>Delete selected wordlist</string>
939-
</property>
940-
</widget>
941-
</item>
942-
<item>
943-
<widget class="QPushButton" name="buttonAddWordList">
944-
<property name="focusPolicy">
945-
<enum>Qt::TabFocus</enum>
946-
</property>
947-
<property name="toolTip">
948-
<string>Add custom wordlist</string>
949-
</property>
950-
<property name="accessibleDescription">
951-
<string>Add custom wordlist</string>
952-
</property>
953-
</widget>
954-
</item>
955-
</layout>
956-
</item>
957-
<item row="4" column="2" alignment="Qt::AlignLeft">
958-
<widget class="QLabel" name="charactersInPassphraseLabel">
937+
<item row="0" column="1" alignment="Qt::AlignRight">
938+
<widget class="QLabel" name="labelWordList">
939+
<property name="sizePolicy">
940+
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
941+
<horstretch>0</horstretch>
942+
<verstretch>0</verstretch>
943+
</sizepolicy>
944+
</property>
959945
<property name="text">
960-
<string>character</string>
946+
<string>Wordlist:</string>
961947
</property>
962948
</widget>
963949
</item>

tests/gui/TestGui.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,12 @@ void TestGui::testDicewareEntryEntropy()
10271027
// Verify entropy and strength
10281028
auto* entropyLabel = pwGeneratorWidget->findChild<QLabel*>("entropyLabel");
10291029
auto* strengthLabel = pwGeneratorWidget->findChild<QLabel*>("strengthLabel");
1030-
auto* wordLengthLabel = pwGeneratorWidget->findChild<QLabel*>("charactersInPassphraseLabel");
1030+
auto* wordLengthLabel = pwGeneratorWidget->findChild<QLabel*>("passwordLengthLabel");
10311031

10321032
QTRY_COMPARE_WITH_TIMEOUT(entropyLabel->text(), QString("Entropy: 77.55 bit"), 200);
10331033
QCOMPARE(strengthLabel->text(), QString("Password Quality: Good"));
1034-
QCOMPARE(wordLengthLabel->text().toInt(), pwGeneratorWidget->getGeneratedPassword().size());
1034+
QCOMPARE(wordLengthLabel->text(),
1035+
QString("Characters: %1").arg(QString::number(pwGeneratorWidget->getGeneratedPassword().length())));
10351036

10361037
QTest::mouseClick(generatedPassword, Qt::LeftButton);
10371038
QTest::keyClick(generatedPassword, Qt::Key_Escape););

0 commit comments

Comments
 (0)