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" ) );
60 QgsDebugMsg(
QString(
"signal returned %1 (username=%2, password=%3)" ).arg( ok ?
"true" :
"false", username, password ) );
64 requestCredentials( realm, &username, &password, message, &ok );
69 void QgsCredentialDialog::requestCredentials(
const QString& realm,
QString *username,
QString *password,
const QString& message,
bool *ok )
73 stackedWidget->setCurrentIndex( 0 );
75 labelRealm->setText( realm );
76 leUsername->setText( *username );
77 lePassword->setText( *password );
78 labelMessage->setText( message );
79 labelMessage->setHidden( message.
isEmpty() );
81 if ( !leUsername->text().isEmpty() )
82 lePassword->setFocus();
84 QWidget *activeWindow = qApp->activeWindow();
89 *ok =
exec() == QDialog::Accepted;
95 activeWindow->
raise();
99 *username = leUsername->text();
100 *password = lePassword->text();
114 requestCredentialsMasterPassword( &password, stored, &ok );
119 void QgsCredentialDialog::requestCredentialsMasterPassword(
QString * password,
bool stored ,
bool *ok )
122 stackedWidget->setCurrentIndex( 1 );
123 leMasterPass->setFocus();
125 QString titletxt( stored ?
tr(
"Enter CURRENT master authentication password" ) :
tr(
"Set NEW master authentication password" ) );
126 lblPasswordTitle->setText( titletxt );
128 leMasterPassVerify->setVisible( !stored );
129 lblDontForget->setVisible( !stored );
133 grpbxPassAttempts->setVisible(
false );
139 if ( passfailed >= 3 )
141 lblSavedForSession->setVisible(
false );
142 grpbxPassAttempts->setTitle(
tr(
"Password attempts: %1" ).arg( passfailed ) );
143 grpbxPassAttempts->setVisible(
true );
152 *ok =
exec() == QDialog::Accepted;
157 bool passok = !leMasterPass->text().isEmpty();
158 if ( passok && stored && !chkbxEraseAuthDb->isChecked() )
163 if ( passok && !stored )
165 passok = ( leMasterPass->text() == leMasterPassVerify->text() );
168 if ( passok || chkbxEraseAuthDb->isChecked() )
170 if ( stored && chkbxEraseAuthDb->isChecked() )
176 *password = leMasterPass->text();
186 if ( leMasterPassVerify->isVisible() )
197 if ( passfailed >= 5 )
204 leMasterPass->
clear();
205 chkMasterPassShow->setChecked(
false );
206 leMasterPassVerify->clear();
208 chkbxEraseAuthDb->setChecked(
false );
209 lblSavedForSession->setVisible(
true );
217 if ( passfailed >= 5 )
223 void QgsCredentialDialog::on_chkMasterPassShow_stateChanged(
int state )
225 leMasterPass->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
226 leMasterPassVerify->setEchoMode(( state > 0 ) ? QLineEdit::Normal : QLineEdit::Password );
229 void QgsCredentialDialog::on_leMasterPass_textChanged(
const QString &pass )
231 leMasterPass->setStyleSheet(
"" );
233 if ( leMasterPassVerify->isVisible() )
235 leMasterPassVerify->setStyleSheet(
"" );
236 passok = passok && ( leMasterPass->text() == leMasterPassVerify->text() );
240 if ( leMasterPassVerify->isVisible() && !passok )
247 void QgsCredentialDialog::on_leMasterPassVerify_textChanged(
const QString &pass )
249 if ( leMasterPassVerify->isVisible() )
251 leMasterPass->setStyleSheet(
"" );
252 leMasterPassVerify->setStyleSheet(
"" );
255 bool passok = !pass.
isEmpty() && ( leMasterPass->text() == leMasterPassVerify->text() );
265 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