23 #include <QPushButton> 29 return QString(
"%1{color: rgb(200, 0, 0);}" ).
arg( selector );
34 , mOkButton( nullptr )
40 Qt::BlockingQueuedConnection );
42 this, SLOT( requestCredentialsMasterPassword(
QString *,
bool,
bool * ) ),
43 Qt::BlockingQueuedConnection );
44 mOkButton = buttonBox->button( QDialogButtonBox::Ok );
45 leMasterPass->setPlaceholderText(
tr(
"Required" ) );
59 QgsDebugMsg(
QString(
"signal returned %1 (username=%2, password=%3)" ).arg( ok ?
"true" :
"false", username, password ) );
63 requestCredentials( realm, &username, &password, message, &ok );
68 void QgsCredentialDialog::requestCredentials(
const QString& realm,
QString *username,
QString *password,
const QString& message,
bool *ok )
72 stackedWidget->setCurrentIndex( 0 );
74 labelRealm->setText( realm );
75 leUsername->setText( *username );
76 lePassword->setText( *password );
77 labelMessage->setText( message );
78 labelMessage->setHidden( message.
isEmpty() );
80 if ( !leUsername->text().isEmpty() )
81 lePassword->setFocus();
83 QWidget *activeWindow = qApp->activeWindow();
88 *ok =
exec() == QDialog::Accepted;
94 activeWindow->
raise();
98 *username = leUsername->text();
99 *password = lePassword->text();
113 requestCredentialsMasterPassword( &password, stored, &ok );
118 void QgsCredentialDialog::requestCredentialsMasterPassword(
QString * password,
bool stored ,
bool *ok )
121 stackedWidget->setCurrentIndex( 1 );
123 QString titletxt( stored ?
tr(
"Enter CURRENT master authentication password" ) :
tr(
"Set NEW master authentication password" ) );
124 lblPasswordTitle->setText( titletxt );
126 leMasterPassVerify->setVisible( !stored );
127 lblDontForget->setVisible( !stored );
131 grpbxPassAttempts->setVisible(
false );
137 if ( passfailed >= 3 )
139 lblSavedForSession->setVisible(
false );
140 grpbxPassAttempts->setTitle(
tr(
"Password attempts: %1" ).arg( passfailed ) );
141 grpbxPassAttempts->setVisible(
true );
150 *ok =
exec() == QDialog::Accepted;
155 bool passok = !leMasterPass->text().isEmpty();
156 if ( passok && stored && !chkbxEraseAuthDb->isChecked() )
161 if ( passok && !stored )
163 passok = ( leMasterPass->text() == leMasterPassVerify->text() );
166 if ( passok || chkbxEraseAuthDb->isChecked() )
168 if ( stored && chkbxEraseAuthDb->isChecked() )
174 *password = leMasterPass->text();
184 if ( leMasterPassVerify->isVisible() )
195 if ( passfailed >= 5 )
202 leMasterPass->
clear();
203 chkMasterPassShow->setChecked(
false );
204 leMasterPassVerify->clear();
206 chkbxEraseAuthDb->setChecked(
false );
207 lblSavedForSession->setVisible(
true );
215 if ( passfailed >= 5 )
221 void QgsCredentialDialog::on_chkMasterPassShow_stateChanged(
int state )
223 leMasterPass->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
224 leMasterPassVerify->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
227 void QgsCredentialDialog::on_leMasterPass_textChanged(
const QString &pass )
229 leMasterPass->setStyleSheet(
"" );
231 if ( leMasterPassVerify->isVisible() )
233 leMasterPassVerify->setStyleSheet(
"" );
234 passok = passok && ( leMasterPass->text() == leMasterPassVerify->text() );
238 if ( leMasterPassVerify->isVisible() && !passok )
245 void QgsCredentialDialog::on_leMasterPassVerify_textChanged(
const QString &pass )
247 if ( leMasterPassVerify->isVisible() )
249 leMasterPass->setStyleSheet(
"" );
250 leMasterPassVerify->setStyleSheet(
"" );
253 bool passok = !pass.
isEmpty() && ( leMasterPass->text() == leMasterPassVerify->text() );
263 void QgsCredentialDialog::on_chkbxEraseAuthDb_toggled(
bool checked )
static QgsAuthManager * instance()
Enforce singleton pattern.
QgsCredentialDialog(QWidget *parent=nullptr, const Qt::WindowFlags &fl=QgisGui::ModalDialogFlags)
QString tr(const char *sourceText, const char *disambiguation, int n)
void credentialsRequested(const QString &, QString *, QString *, const QString &, bool *)
static QString invalidStyle_(const QString &selector="QLineEdit")
void setOverrideCursor(const QCursor &cursor)
virtual bool request(const QString &realm, QString &username, QString &password, const QString &message=QString::null) override
request a password
void restoreOverrideCursor()
virtual QSize sizeHint() const
void setScheduledAuthDbErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
QThread * currentThread()
bool verifyMasterPassword(const QString &compare=QString::null)
Verify the supplied master password against any existing hash in authentication database.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual bool requestMasterPassword(QString &password, bool stored=false) override
request a master password
void credentialsRequestedMasterPassword(QString *, bool, bool *)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setInstance(QgsCredentials *theInstance)
register instance