Skip to content

Commit dfb476a

Browse files
committed
[auth] Fix #13568; disable auth system after 5 wrong password attempts
1 parent b65b595 commit dfb476a

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

src/core/auth/qgsauthmanager.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,14 @@ bool QgsAuthManager::verifyMasterPassword( const QString &compare )
512512

513513
emit masterPasswordVerified( false );
514514
}
515+
++mPassTries;
516+
if ( mPassTries >= 5 )
517+
{
518+
mAuthDisabled = true;
519+
const char* err = QT_TR_NOOP( "Master password: failed 5 times authentication system DISABLED" );
520+
QgsDebugMsg( err );
521+
emit messageOut( tr( err ), authManTag(), WARNING );
522+
}
515523
return false;
516524
}
517525
else
@@ -2800,6 +2808,7 @@ QgsAuthManager::QgsAuthManager()
28002808
, mAuthDbPath( QString() )
28012809
, mQcaInitializer( 0 )
28022810
, mMasterPass( QString() )
2811+
, mPassTries( 0 )
28032812
, mAuthDisabled( false )
28042813
, mScheduledDbEraseTimer( 0 )
28052814
, mScheduledDbErase( false )

src/core/auth/qgsauthmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ class CORE_EXPORT QgsAuthManager : public QObject
607607
QHash<QString, QgsAuthMethod*> mAuthMethods;
608608

609609
QString mMasterPass;
610+
int mPassTries;
610611
bool mAuthDisabled;
611612
QString mAuthDisabledMessage;
612613
QTimer *mScheduledDbEraseTimer;

src/gui/auth/qgsauthmasterpassresetdialog.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ void QgsMasterPasswordResetDialog::on_leMasterPassCurrent_textChanged( const QSt
7373
{
7474
// since this is called on every keystroke, block signals emitted during verification of password
7575
QgsAuthManager::instance()->blockSignals( true );
76-
mPassCurOk = !pass.isEmpty() && QgsAuthManager::instance()->setMasterPassword( pass, true );
76+
mPassCurOk = !pass.isEmpty();
7777
QgsAuthManager::instance()->blockSignals( false );
7878
validatePasswords();
7979
}
8080

8181
void QgsMasterPasswordResetDialog::on_leMasterPassNew_textChanged( const QString& pass )
8282
{
83-
mPassNewOk = !pass.isEmpty() && !QgsAuthManager::instance()->masterPasswordSame( pass );
83+
mPassNewOk = !pass.isEmpty();
8484
validatePasswords();
8585
}
8686

@@ -96,10 +96,12 @@ void QgsMasterPasswordResetDialog::on_chkPassShowNew_stateChanged( int state )
9696

9797
void QgsMasterPasswordResetDialog::validatePasswords()
9898
{
99-
QString ss = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( "QLineEdit" )
100-
: QgsAuthGuiUtils::redTextStyleSheet( "QLineEdit" );
101-
leMasterPassCurrent->setStyleSheet( ss );
102-
leMasterPassNew->setStyleSheet( ss );
99+
QString ss1 = mPassCurOk ? QgsAuthGuiUtils::greenTextStyleSheet( "QLineEdit" )
100+
: QgsAuthGuiUtils::redTextStyleSheet( "QLineEdit" );
101+
leMasterPassCurrent->setStyleSheet( ss1 );
102+
QString ss2 = mPassNewOk ? QgsAuthGuiUtils::greenTextStyleSheet( "QLineEdit" )
103+
: QgsAuthGuiUtils::redTextStyleSheet( "QLineEdit" );
104+
leMasterPassNew->setStyleSheet( ss2 );
103105
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( mPassCurOk && mPassNewOk );
104106
}
105107

src/gui/qgscredentialdialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ void QgsCredentialDialog::requestCredentialsMasterPassword( QString * password,
190190
{
191191
break;
192192
}
193+
194+
if ( passfailed >= 5 )
195+
{
196+
break;
197+
}
193198
}
194199

195200
// don't leave master password in singleton's text field, or the ability to show it
@@ -205,6 +210,11 @@ void QgsCredentialDialog::requestCredentialsMasterPassword( QString * password,
205210
mOkButton->setEnabled( true );
206211

207212
QApplication::restoreOverrideCursor();
213+
214+
if ( passfailed >= 5 )
215+
{
216+
close();
217+
}
208218
}
209219

210220
void QgsCredentialDialog::on_chkMasterPassShow_stateChanged( int state )

0 commit comments

Comments
 (0)