Skip to content

Commit

Permalink
Add new password confirmation step to reset master password dialog
Browse files Browse the repository at this point in the history
Users must now enter the new password twice, so that eg a typo
in the new password dialog won't result in an un-decryptable
database.
  • Loading branch information
nyalldawson committed Feb 4, 2025
1 parent 57979ff commit 5ae9dfe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/gui/auth/qgsauthmasterpassresetdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ QgsMasterPasswordResetDialog::QgsMasterPasswordResetDialog( QWidget *parent )
setupUi( this );
connect( leMasterPassCurrent, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
connect( leMasterPassNew, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );
connect( leMasterPassNew2, &QgsPasswordLineEdit::textChanged, this, &QgsMasterPasswordResetDialog::validatePasswords );

if ( QgsApplication::authManager()->sqliteDatabasePath().isEmpty() )
{
Expand Down Expand Up @@ -74,15 +75,20 @@ void QgsMasterPasswordResetDialog::validatePasswords()
{
const QString currentPassword = leMasterPassCurrent->text();
const QString newPassword = leMasterPassNew->text();
const QString confirmPassword = leMasterPassNew2->text();

const bool currentPasswordOk = !currentPassword.isEmpty();
const bool newPasswordOk = !newPassword.isEmpty();
const bool confirmPasswordOk = !confirmPassword.isEmpty() && confirmPassword == newPassword;

const QString ss1 = currentPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassCurrent->setStyleSheet( ss1 );
const QString ss2 = newPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassNew->setStyleSheet( ss2 );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk );
const QString ss3 = confirmPasswordOk ? QgsAuthGuiUtils::greenTextStyleSheet( QStringLiteral( "QLineEdit" ) )
: QgsAuthGuiUtils::redTextStyleSheet( QStringLiteral( "QLineEdit" ) );
leMasterPassNew2->setStyleSheet( ss3 );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( currentPasswordOk && newPasswordOk && confirmPasswordOk );
}
25 changes: 25 additions & 0 deletions src/ui/auth/qgsauthmasterpassresetdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_8">
<property name="font">
<font>
<italic>false</italic>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Re-enter NEW password</string>
</property>
</widget>
</item>
<item>
<widget class="QgsPasswordLineEdit" name="leMasterPassNew2">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string>Required</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkKeepBackup">
<property name="text">
Expand Down Expand Up @@ -121,6 +144,8 @@ and re-encrypted using new password</string>
<tabstops>
<tabstop>leMasterPassCurrent</tabstop>
<tabstop>leMasterPassNew</tabstop>
<tabstop>leMasterPassNew2</tabstop>
<tabstop>chkKeepBackup</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down

0 comments on commit 5ae9dfe

Please sign in to comment.