• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDE3Support

k3passworddialog.cpp

Go to the documentation of this file.
00001 // vi: ts=8 sts=4 sw=4
00002 /* This file is part of the KDE libraries
00003    Copyright (C) 1998 Pietro Iglio <iglio@fub.it>
00004    Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
00005    Copyright (C) 2004,2005 Andrew Coles <andrew_coles@yahoo.co.uk>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "k3passworddialog.h"
00023 
00024 #include <sys/time.h>
00025 #include <sys/resource.h>
00026 
00027 #include <QtCore/QCoreApplication>
00028 #include <QtCore/QRegExp>
00029 #include <QtCore/QSize>
00030 #include <QtCore/QString>
00031 #include <QtGui/QCheckBox>
00032 #include <QtGui/QLabel>
00033 #include <QtGui/QLayout>
00034 #include <QtGui/QKeyEvent>
00035 #include <QtGui/QProgressBar>
00036 #include <QtGui/QWidget>
00037 
00038 #include <Q3PtrDict>
00039 
00040 #include <kconfig.h>
00041 #include <kglobal.h>
00042 #include <khbox.h>
00043 #include <kiconloader.h>
00044 #include <klocale.h>
00045 #include <kmessagebox.h>
00046 
00047 #include <kconfiggroup.h>
00048 
00049 /*
00050  * Password line editor.
00051  */
00052 
00053 // BCI: Add a real d-pointer and put the int into that
00054 
00055 static Q3PtrDict<int>* d_ptr = 0;
00056 
00057 static void cleanup_d_ptr() {
00058     delete d_ptr;
00059 }
00060 
00061 static int * ourMaxLength( const K3PasswordEdit* const e ) {
00062     if ( !d_ptr ) {
00063         d_ptr = new Q3PtrDict<int>;
00064         d_ptr->setAutoDelete(true);
00065         qAddPostRoutine( cleanup_d_ptr );
00066     }
00067     int* ret = d_ptr->find( (void*) e );
00068     if ( ! ret ) {
00069         ret = new int;
00070         d_ptr->replace( (void*) e, ret );
00071     }
00072     return ret;
00073 }
00074 
00075 static void delete_d( const K3PasswordEdit* const e ) {
00076     if ( d_ptr )
00077         d_ptr->remove( (void*) e );
00078 }
00079 
00080 const int K3PasswordEdit::PassLen = 200;
00081 
00082 class K3PasswordDialog::K3PasswordDialogPrivate
00083 {
00084     public:
00085     K3PasswordDialogPrivate()
00086      : m_MatchLabel( 0 ), iconName( 0 ), allowEmptyPasswords( false ),
00087        minimumPasswordLength(0), maximumPasswordLength(K3PasswordEdit::PassLen - 1),
00088        passwordStrengthWarningLevel(1), m_strengthBar(0),
00089        reasonablePasswordLength(8)
00090         {}
00091     QLabel *m_MatchLabel;
00092     QString iconName;
00093     bool allowEmptyPasswords;
00094     int minimumPasswordLength;
00095     int maximumPasswordLength;
00096     int passwordStrengthWarningLevel;
00097     QProgressBar* m_strengthBar;
00098     int reasonablePasswordLength;
00099 };
00100 
00101 
00102 K3PasswordEdit::K3PasswordEdit(QWidget *parent) : QLineEdit(parent)
00103 {
00104     init();
00105 
00106     KConfigGroup cg(KGlobal::config(), "Passwords");
00107 
00108     const QString val = cg.readEntry("EchoMode", "OneStar");
00109     if (val == "ThreeStars")
00110     m_EchoMode = ThreeStars;
00111     else if (val == "NoEcho")
00112     m_EchoMode = NoEcho;
00113     else
00114     m_EchoMode = OneStar;
00115 
00116 }
00117 
00118 K3PasswordEdit::K3PasswordEdit(EchoModes echoMode, QWidget *parent)
00119     : QLineEdit(parent), m_EchoMode(echoMode)
00120 {
00121     init();
00122 }
00123 
00124 K3PasswordEdit::K3PasswordEdit(EchoMode echoMode, QWidget *parent)
00125     : QLineEdit(parent)
00126     , m_EchoMode( echoMode == QLineEdit::NoEcho ? NoEcho : OneStar )
00127 {
00128     init();
00129 }
00130 
00131 void K3PasswordEdit::init()
00132 {
00133     setEchoMode(QLineEdit::Password); // Just in case
00134     setAcceptDrops(false);
00135     int* t = ourMaxLength(this);
00136     *t = (PassLen - 1); // the internal max length
00137     m_Password = new char[PassLen];
00138     m_Password[0] = '\000';
00139     m_Length = 0;
00140 }
00141 
00142 K3PasswordEdit::~K3PasswordEdit()
00143 {
00144     memset(m_Password, 0, PassLen * sizeof(char));
00145     delete[] m_Password;
00146     delete_d(this);
00147 }
00148 
00149 const char *K3PasswordEdit::password() const
00150 {
00151     return m_Password;
00152 }
00153 
00154 void K3PasswordEdit::insert(const QString &txt)
00155 {
00156     const QByteArray localTxt = txt.toLocal8Bit();
00157     const unsigned int lim = localTxt.length();
00158     const int m_MaxLength = maxPasswordLength();
00159     for(unsigned int i=0; i < lim; ++i)
00160     {
00161         const unsigned char ke = localTxt[i];
00162         if (m_Length < m_MaxLength)
00163         {
00164             m_Password[m_Length] = ke;
00165             m_Password[++m_Length] = '\000';
00166         }
00167     }
00168     showPass();
00169 }
00170 
00171 void K3PasswordEdit::erase()
00172 {
00173     m_Length = 0;
00174     memset(m_Password, 0, PassLen * sizeof(char));
00175     setText("");
00176 }
00177 
00178 void K3PasswordEdit::focusInEvent(QFocusEvent *e)
00179 {
00180     const QString txt = text();
00181     setUpdatesEnabled(false);
00182     QLineEdit::focusInEvent(e);
00183     setUpdatesEnabled(true);
00184     setText(txt);
00185 }
00186 
00187 
00188 void K3PasswordEdit::keyPressEvent(QKeyEvent *e)
00189 {
00190     switch (e->key()) {
00191     case Qt::Key_Return:
00192     case Qt::Key_Enter:
00193     case Qt::Key_Escape:
00194     e->ignore();
00195     break;
00196     case Qt::Key_Backspace:
00197     case Qt::Key_Delete:
00198     case 0x7f: // Delete
00199     if (e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))
00200         e->ignore();
00201     else if (m_Length) {
00202         m_Password[--m_Length] = '\000';
00203         showPass();
00204     }
00205     break;
00206     default:
00207     const unsigned char ke = e->text().toLocal8Bit()[0];
00208     if (ke >= 32) {
00209         insert(e->text());
00210     } else
00211         e->ignore();
00212     break;
00213     }
00214 }
00215 
00216 bool K3PasswordEdit::event(QEvent *e) {
00217     switch(e->type()) {
00218 
00219       case QEvent::MouseButtonPress:
00220       case QEvent::MouseButtonRelease:
00221       case QEvent::MouseButtonDblClick:
00222       case QEvent::MouseMove:
00223         return true; //Ignore
00224       case QEvent::InputMethod:
00225       {
00226         QInputMethodEvent* const ie = (QInputMethodEvent*) e;
00227         if (!ie->commitString().isNull())
00228             insert( ie->commitString() );
00229         return true;
00230       }
00231 
00232       case QEvent::ShortcutOverride:
00233       {
00234         QKeyEvent* const k = (QKeyEvent*) e;
00235         switch (k->key()) {
00236             case Qt::Key_U:
00237                 if (k->modifiers() & Qt::ControlModifier) {
00238                     m_Length = 0;
00239                     m_Password[m_Length] = '\000';
00240                     showPass();
00241                 }
00242         }
00243         return true; // stop bubbling
00244       }
00245 
00246       default:
00247         // Do nothing
00248         break;
00249     }
00250     return QLineEdit::event(e);
00251 }
00252 
00253 void K3PasswordEdit::showPass()
00254 {
00255     QString tmp;
00256 
00257     switch (m_EchoMode) {
00258     case OneStar:
00259     tmp.fill('*', m_Length);
00260     setText(tmp);
00261     break;
00262     case ThreeStars:
00263     tmp.fill('*', m_Length*3);
00264     setText(tmp);
00265     break;
00266     case NoEcho: default:
00267     emit textChanged(QString()); //To update the password comparison if need be.
00268     break;
00269     }
00270 }
00271 
00272 void K3PasswordEdit::setMaxPasswordLength(int newLength)
00273 {
00274     if (newLength >= PassLen) newLength = PassLen - 1; // belt and braces
00275     if (newLength < 0) newLength = 0;
00276     int* t = ourMaxLength(this);
00277     *t = newLength; 
00278     while (m_Length > newLength) {
00279         m_Password[m_Length] = '\000';
00280         --m_Length;
00281     }
00282     showPass();
00283 }
00284 
00285 int K3PasswordEdit::maxPasswordLength() const
00286 {
00287     return *(ourMaxLength(this));
00288 }
00289 /*
00290  * Password dialog.
00291  */
00292 
00293 K3PasswordDialog::K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn,
00294                                  QWidget *parent)
00295     : KDialog(parent, Qt::Dialog)
00296       , m_Keep(enableKeep? 1 : 0), m_Type(type), d(new K3PasswordDialogPrivate)
00297 {
00298     setButtons( Ok|Cancel|extraBttn );
00299     setModal( true );
00300     showButtonSeparator( true );
00301     setDefaultButton( Ok );
00302     d->iconName = "password";
00303     init();
00304 }
00305 
00306 K3PasswordDialog::K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn, const QString& icon,
00307                   QWidget *parent)
00308     : KDialog(parent, Qt::Dialog)
00309       , m_Keep(enableKeep? 1 : 0), m_Type(type), d(new K3PasswordDialogPrivate)
00310 {
00311     setButtons( Ok|Cancel|extraBttn );
00312     setModal( true );
00313     showButtonSeparator( true );
00314     setDefaultButton( Ok );
00315     if ( icon.trimmed().isEmpty() )
00316     d->iconName = "password";
00317     else
00318     d->iconName = icon;
00319     init();
00320 }
00321 
00322 
00323 void K3PasswordDialog::init()
00324 {
00325     m_Row = 0;
00326 
00327     KConfigGroup cg(KGlobal::config(), "Passwords");
00328     if (m_Keep && cg.readEntry("Keep", false))
00329     ++m_Keep;
00330 
00331     m_pMain = new QWidget(this);
00332     setMainWidget(m_pMain);
00333     m_pGrid = new QGridLayout(m_pMain);
00334     m_pGrid->setMargin(0);
00335     m_pGrid->setSpacing(0);
00336 
00337     // Row 1: pixmap + prompt
00338     QLabel *lbl;
00339     const QPixmap pix( KIconLoader::global()->loadIcon( d->iconName, KIconLoader::NoGroup, KIconLoader::SizeHuge, 0, QStringList(), 0, true));
00340     if (!pix.isNull()) {
00341     lbl = new QLabel(m_pMain);
00342     lbl->setPixmap(pix);
00343     lbl->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
00344     lbl->setFixedSize(lbl->sizeHint());
00345     m_pGrid->addWidget(lbl, 0, 0, Qt::AlignCenter);
00346     }
00347 
00348     m_pHelpLbl = new QLabel(m_pMain);
00349     m_pHelpLbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00350     m_pHelpLbl->setWordWrap(true);
00351     m_pGrid->addWidget(m_pHelpLbl, 0, 2, Qt::AlignLeft);
00352     m_pGrid->setRowStretch(1, 12);
00353 
00354     // Row 2+: space for 4 extra info lines
00355     m_pGrid->setRowStretch(6, 12);
00356 
00357     // Row 3: Password editor #1
00358     lbl = new QLabel(m_pMain);
00359     lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00360     lbl->setText(i18n("&Password:"));
00361     lbl->setFixedSize(lbl->sizeHint());
00362     m_pGrid->addWidget(lbl, 7, 0, Qt::AlignLeft);
00363 
00364     QHBoxLayout *h_lay = new QHBoxLayout();
00365     m_pGrid->addLayout(h_lay, 7, 2);
00366     m_pEdit = new K3PasswordEdit(m_pMain);
00367     m_pEdit2 = 0;
00368     lbl->setBuddy(m_pEdit);
00369     QSize size = m_pEdit->sizeHint();
00370     m_pEdit->setFixedHeight(size.height());
00371     m_pEdit->setMinimumWidth(size.width());
00372     h_lay->addWidget(m_pEdit);
00373 
00374     // Row 4: Password editor #2 or keep password checkbox
00375 
00376     if ((m_Type == Password) && m_Keep) {
00377     m_pGrid->setRowStretch(8, 12);
00378     QCheckBox* const cb = new QCheckBox(i18n("&Keep password"), m_pMain);
00379     cb->setFixedSize(cb->sizeHint());
00380     if (m_Keep > 1)
00381         cb->setChecked(true);
00382     else
00383         m_Keep = 0;
00384     connect(cb, SIGNAL(toggled(bool)), SLOT(slotKeep(bool)));
00385     m_pGrid->addWidget(cb, 9, 2, Qt::AlignLeft|Qt::AlignVCenter);
00386     } else if (m_Type == NewPassword) {
00387     lbl = new QLabel(m_pMain);
00388     lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00389     lbl->setText(i18n("&Verify:"));
00390     lbl->setFixedSize(lbl->sizeHint());
00391     m_pGrid->addWidget(lbl, 9, 0, Qt::AlignLeft);
00392 
00393     h_lay = new QHBoxLayout();
00394     m_pGrid->addLayout(h_lay, 9, 2);
00395     m_pEdit2 = new K3PasswordEdit(m_pMain);
00396     lbl->setBuddy(m_pEdit2);
00397     size = m_pEdit2->sizeHint();
00398     m_pEdit2->setFixedHeight(size.height());
00399     m_pEdit2->setMinimumWidth(size.width());
00400     h_lay->addWidget(m_pEdit2);
00401 
00402         // Row 6: Password strength meter
00403         m_pGrid->setRowStretch(10, 12);
00404 
00405         KHBox* const strengthBox = new KHBox(m_pMain);
00406         strengthBox->setSpacing(10);
00407         m_pGrid->addWidget(strengthBox, 11, 0, 1, 3);
00408         QLabel* const passStrengthLabel = new QLabel(strengthBox);
00409         passStrengthLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00410         passStrengthLabel->setText(i18n("Password strength meter:"));
00411         d->m_strengthBar = new QProgressBar(strengthBox);
00412         d->m_strengthBar->setObjectName("PasswordStrengthMeter");
00413         d->m_strengthBar->setRange(0, 100);
00414         d->m_strengthBar->setTextVisible(false);
00415 
00416         const QString strengthBarWhatsThis(i18n("The password strength meter gives an indication of the security "
00417                                                 "of the password you have entered.  To improve the strength of "
00418                                                 "the password, try:\n"
00419                                                 " - using a longer password;\n"
00420                                                 " - using a mixture of upper- and lower-case letters;\n"
00421                                                 " - using numbers or symbols, such as #, as well as letters."));
00422         passStrengthLabel->setWhatsThis(strengthBarWhatsThis);
00423         d->m_strengthBar->setWhatsThis(strengthBarWhatsThis);
00424 
00425         // Row 6: Label saying whether the passwords match
00426         m_pGrid->setRowStretch(12, 12);
00427 
00428         d->m_MatchLabel = new QLabel(m_pMain);
00429         d->m_MatchLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00430         d->m_MatchLabel->setWordWrap(true);
00431         m_pGrid->addWidget(d->m_MatchLabel, 13, 0, 1, 3);
00432         d->m_MatchLabel->setText(i18n("Passwords do not match"));
00433 
00434 
00435         connect( m_pEdit, SIGNAL(textChanged(const QString&)), SLOT(enableOkBtn()) );
00436         connect( m_pEdit2, SIGNAL(textChanged(const QString&)), SLOT(enableOkBtn()) );
00437         enableOkBtn();
00438     }
00439 
00440     erase();
00441 }
00442 
00443 
00444 K3PasswordDialog::~K3PasswordDialog()
00445 {
00446     delete d;
00447 }
00448 
00449 
00450 void K3PasswordDialog::clearPassword()
00451 {
00452     m_pEdit->erase();
00453 }
00454 
00455 void K3PasswordDialog::setPrompt(const QString &prompt)
00456 {
00457     m_pHelpLbl->setText(prompt);
00458     m_pHelpLbl->setFixedSize(275, m_pHelpLbl->heightForWidth(275));
00459 }
00460 
00461 
00462 QString K3PasswordDialog::prompt() const
00463 
00464 {
00465     return m_pHelpLbl->text();
00466 }
00467 
00468 
00469 void K3PasswordDialog::addLine(const QString &key, const QString &value)
00470 {
00471     if (m_Row > 3)
00472     return;
00473 
00474     QLabel *lbl = new QLabel(key, m_pMain);
00475     lbl->setAlignment(Qt::AlignLeft|Qt::AlignTop);
00476     lbl->setFixedSize(lbl->sizeHint());
00477     m_pGrid->addWidget(lbl, m_Row+2, 0, Qt::AlignLeft);
00478 
00479     lbl = new QLabel(value, m_pMain);
00480     lbl->setAlignment(Qt::AlignTop);
00481     lbl->setWordWrap(true);
00482     lbl->setFixedSize(275, lbl->heightForWidth(275));
00483     m_pGrid->addWidget(lbl, m_Row+2, 2, Qt::AlignLeft);
00484     ++m_Row;
00485 }
00486 
00487 
00488 void K3PasswordDialog::erase()
00489 {
00490     m_pEdit->erase();
00491     m_pEdit->setFocus();
00492     if (m_Type == NewPassword)
00493     m_pEdit2->erase();
00494 }
00495 
00496 
00497 void K3PasswordDialog::accept()
00498 {
00499     if (m_Type == NewPassword) {
00500     if (strcmp(m_pEdit->password(), m_pEdit2->password())) {
00501         KMessageBox::sorry(this, i18n("You entered two different "
00502             "passwords. Please try again."));
00503         erase();
00504         return;
00505     }
00506     if (d->m_strengthBar && d->m_strengthBar->value() < d->passwordStrengthWarningLevel) {
00507         int retVal = KMessageBox::warningContinueCancel(this,
00508         i18n(   "The password you have entered has a low strength. "
00509             "To improve the strength of "
00510             "the password, try:\n"
00511             " - using a longer password;\n"
00512             " - using a mixture of upper- and lower-case letters;\n"
00513             " - using numbers or symbols as well as letters.\n"
00514             "\n"
00515             "Would you like to use this password anyway?"),
00516         i18n("Low Password Strength"));
00517         if (retVal == KMessageBox::Cancel) return;
00518     }
00519     }
00520     if (!checkPassword(m_pEdit->password())) {
00521     erase();
00522     return;
00523     }
00524     KDialog::accept();
00525 }
00526 
00527 
00528 
00529 
00530 void K3PasswordDialog::slotKeep(bool keep)
00531 {
00532     m_Keep = keep;
00533 }
00534 
00535 bool K3PasswordDialog::checkPassword(const char *)
00536 {
00537     return true;
00538 }
00539 
00540 
00541 int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &caption,
00542     const QString &prompt, bool *keep)
00543 {
00544     const bool enableKeep = (keep && *keep);
00545     K3PasswordDialog* const dlg = new K3PasswordDialog(Password, enableKeep,false,parent);
00546     dlg->setWindowTitle(caption);
00547     dlg->setPrompt(prompt);
00548     const int ret = dlg->exec();
00549     if (ret == Accepted) {
00550     password = dlg->password();
00551     if (enableKeep)
00552         *keep = dlg->keep();
00553     }
00554     delete dlg;
00555     return ret;
00556 }
00557 
00558 int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &prompt,
00559     int *keep)
00560 {
00561     int res = K3PasswordDialog::Rejected;
00562     if (keep) {
00563         bool boolkeep = *keep;
00564         res = getPassword(parent, password, i18n("Password Input"), prompt, &boolkeep);
00565         *keep = boolkeep;
00566     }
00567     else {
00568         res = getPassword(parent, password, i18n("Password Input"), prompt);
00569     }
00570     return res;
00571 }
00572 
00573 
00574 int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &caption,
00575     const QString &prompt)
00576 {
00577     K3PasswordDialog* const dlg = new K3PasswordDialog(NewPassword, false,false,parent);
00578     dlg->setWindowTitle(caption);
00579     dlg->setPrompt(prompt);
00580     const int ret = dlg->exec();
00581     if (ret == Accepted)
00582     password = dlg->password();
00583     delete dlg;
00584     return ret;
00585 }
00586 
00587 int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &prompt)
00588 {
00589     return getNewPassword(parent, password, i18n("Password Input"), prompt);
00590 }
00591 
00592 
00593 // static
00594 void K3PasswordDialog::disableCoreDumps()
00595 {
00596     struct rlimit rlim;
00597     rlim.rlim_cur = rlim.rlim_max = 0;
00598     setrlimit(RLIMIT_CORE, &rlim);
00599 }
00600 
00601 
00602 void K3PasswordDialog::enableOkBtn()
00603 {
00604     if (m_Type == NewPassword) {
00605       const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0
00606                    && (d->allowEmptyPasswords || m_pEdit->password()[0]);
00607 
00608       const QString pass(m_pEdit->password());
00609 
00610       const int minPasswordLength = minimumPasswordLength();
00611 
00612       if ((int) pass.length() < minPasswordLength) {
00613           enableButtonOk(false);
00614       } else {
00615           enableButtonOk( match );
00616       }
00617 
00618       if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) {
00619           d->m_MatchLabel->setText( i18n("Password is empty") );
00620       } else {
00621           if ((int) pass.length() < minPasswordLength) {
00622               d->m_MatchLabel->setText(i18np("Password must be at least 1 character long", "Password must be at least %1 characters long", minPasswordLength));
00623           } else {
00624               d->m_MatchLabel->setText( match? i18n("Passwords match")
00625                                               :i18n("Passwords do not match") );
00626           }
00627       }
00628 
00629       // Password strength calculator
00630       // Based on code in the Master Password dialog in Firefox
00631       // (pref-masterpass.js)
00632       // Original code triple-licensed under the MPL, GPL, and LGPL
00633       // so is license-compatible with this file
00634 
00635       const double lengthFactor = d->reasonablePasswordLength / 8.0;
00636 
00637       
00638       int pwlength = (int) (pass.length() / lengthFactor);
00639       if (pwlength > 5) pwlength = 5;
00640 
00641       const QRegExp numRxp("[0-9]", Qt::CaseSensitive, QRegExp::RegExp);
00642       int numeric = (int) (pass.count(numRxp) / lengthFactor);
00643       if (numeric > 3) numeric = 3;
00644 
00645       const QRegExp symbRxp("\\W", Qt::CaseInsensitive, QRegExp::RegExp);
00646       int numsymbols = (int) (pass.count(symbRxp) / lengthFactor);
00647       if (numsymbols > 3) numsymbols = 3;
00648 
00649       const QRegExp upperRxp("[A-Z]", Qt::CaseSensitive, QRegExp::RegExp);
00650       int upper = (int) (pass.count(upperRxp) / lengthFactor);
00651       if (upper > 3) upper = 3;
00652 
00653       int pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);
00654 
00655       if ( pwstrength < 0 ) {
00656           pwstrength = 0;
00657       }
00658   
00659       if ( pwstrength > 100 ) {
00660           pwstrength = 100;
00661       }
00662       d->m_strengthBar->setValue(pwstrength);
00663 
00664    }
00665 }
00666 
00667 
00668 void K3PasswordDialog::setAllowEmptyPasswords(bool allowed) {
00669     d->allowEmptyPasswords = allowed;
00670     enableOkBtn();
00671 }
00672 
00673 
00674 bool K3PasswordDialog::allowEmptyPasswords() const {
00675     return d->allowEmptyPasswords;
00676 }
00677 
00678 void K3PasswordDialog::setMinimumPasswordLength(int minLength) {
00679     d->minimumPasswordLength = minLength;
00680     enableOkBtn();
00681 }
00682 
00683 int K3PasswordDialog::minimumPasswordLength() const {
00684     return d->minimumPasswordLength;
00685 }
00686 
00687 void K3PasswordDialog::setMaximumPasswordLength(int maxLength) {
00688 
00689     if (maxLength < 0) maxLength = 0;
00690     if (maxLength >= K3PasswordEdit::PassLen) maxLength = K3PasswordEdit::PassLen - 1;
00691 
00692     d->maximumPasswordLength = maxLength;
00693 
00694     m_pEdit->setMaxPasswordLength(maxLength);
00695     if (m_pEdit2) m_pEdit2->setMaxPasswordLength(maxLength);
00696 
00697 }
00698 
00699 int K3PasswordDialog::maximumPasswordLength() const {
00700     return d->maximumPasswordLength;
00701 }
00702 
00703 // reasonable password length code contributed by Steffen Mthing
00704 
00705 void K3PasswordDialog::setReasonablePasswordLength(int reasonableLength) {
00706 
00707     if (reasonableLength < 1) reasonableLength = 1;
00708     if (reasonableLength >= maximumPasswordLength()) reasonableLength = maximumPasswordLength();
00709 
00710     d->reasonablePasswordLength = reasonableLength;
00711 
00712 }
00713 
00714 int K3PasswordDialog::reasonablePasswordLength() const {
00715   return d->reasonablePasswordLength;
00716 }
00717 
00718 
00719 void K3PasswordDialog::setPasswordStrengthWarningLevel(int warningLevel) {
00720     if (warningLevel < 0) warningLevel = 0;
00721     if (warningLevel > 99) warningLevel = 99;
00722     d->passwordStrengthWarningLevel = warningLevel;
00723 }
00724 
00725 int K3PasswordDialog::passwordStrengthWarningLevel() const {
00726     return d->passwordStrengthWarningLevel;
00727 }
00728 
00729 const char *K3PasswordDialog::password() const
00730 {
00731     return m_pEdit->password();
00732 }
00733 
00734 bool K3PasswordDialog::keep() const
00735 {
00736     return m_Keep;
00737 }
00738 
00739 #include "k3passworddialog.moc"

KDE3Support

Skip menu "KDE3Support"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal