• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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 ), 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     setDefaultButton( Ok );
00301     d->iconName = "password";
00302     init();
00303 }
00304 
00305 K3PasswordDialog::K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn, const QString& icon,
00306                   QWidget *parent)
00307     : KDialog(parent, Qt::Dialog)
00308       , m_Keep(enableKeep? 1 : 0), m_Type(type), d(new K3PasswordDialogPrivate)
00309 {
00310     setButtons( Ok|Cancel|extraBttn );
00311     setModal( true );
00312     setDefaultButton( Ok );
00313     if ( icon.trimmed().isEmpty() )
00314     d->iconName = "password";
00315     else
00316     d->iconName = icon;
00317     init();
00318 }
00319 
00320 
00321 void K3PasswordDialog::init()
00322 {
00323     m_Row = 0;
00324 
00325     KConfigGroup cg(KGlobal::config(), "Passwords");
00326     if (m_Keep && cg.readEntry("Keep", false))
00327     ++m_Keep;
00328 
00329     m_pMain = new QWidget(this);
00330     setMainWidget(m_pMain);
00331     m_pGrid = new QGridLayout(m_pMain);
00332     m_pGrid->setMargin(0);
00333     m_pGrid->setSpacing(0);
00334 
00335     // Row 1: pixmap + prompt
00336     QLabel *lbl;
00337     const QPixmap pix( KIconLoader::global()->loadIcon( d->iconName, KIconLoader::NoGroup, KIconLoader::SizeHuge, 0, QStringList(), 0, true));
00338     if (!pix.isNull()) {
00339     lbl = new QLabel(m_pMain);
00340     lbl->setPixmap(pix);
00341     lbl->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
00342     lbl->setFixedSize(lbl->sizeHint());
00343     m_pGrid->addWidget(lbl, 0, 0, Qt::AlignCenter);
00344     }
00345 
00346     m_pHelpLbl = new QLabel(m_pMain);
00347     m_pHelpLbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00348     m_pHelpLbl->setWordWrap(true);
00349     m_pGrid->addWidget(m_pHelpLbl, 0, 2, Qt::AlignLeft);
00350     m_pGrid->setRowStretch(1, 12);
00351 
00352     // Row 2+: space for 4 extra info lines
00353     m_pGrid->setRowStretch(6, 12);
00354 
00355     // Row 3: Password editor #1
00356     lbl = new QLabel(m_pMain);
00357     lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00358     lbl->setText(i18n("&Password:"));
00359     lbl->setFixedSize(lbl->sizeHint());
00360     m_pGrid->addWidget(lbl, 7, 0, Qt::AlignLeft);
00361 
00362     QHBoxLayout *h_lay = new QHBoxLayout();
00363     m_pGrid->addLayout(h_lay, 7, 2);
00364     m_pEdit = new K3PasswordEdit(m_pMain);
00365     m_pEdit2 = 0;
00366     lbl->setBuddy(m_pEdit);
00367     QSize size = m_pEdit->sizeHint();
00368     m_pEdit->setFixedHeight(size.height());
00369     m_pEdit->setMinimumWidth(size.width());
00370     h_lay->addWidget(m_pEdit);
00371 
00372     // Row 4: Password editor #2 or keep password checkbox
00373 
00374     if ((m_Type == Password) && m_Keep) {
00375     m_pGrid->setRowStretch(8, 12);
00376     QCheckBox* const cb = new QCheckBox(i18n("&Keep password"), m_pMain);
00377     cb->setFixedSize(cb->sizeHint());
00378     if (m_Keep > 1)
00379         cb->setChecked(true);
00380     else
00381         m_Keep = 0;
00382     connect(cb, SIGNAL(toggled(bool)), SLOT(slotKeep(bool)));
00383     m_pGrid->addWidget(cb, 9, 2, Qt::AlignLeft|Qt::AlignVCenter);
00384     } else if (m_Type == NewPassword) {
00385     lbl = new QLabel(m_pMain);
00386     lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00387     lbl->setText(i18n("&Verify:"));
00388     lbl->setFixedSize(lbl->sizeHint());
00389     m_pGrid->addWidget(lbl, 9, 0, Qt::AlignLeft);
00390 
00391     h_lay = new QHBoxLayout();
00392     m_pGrid->addLayout(h_lay, 9, 2);
00393     m_pEdit2 = new K3PasswordEdit(m_pMain);
00394     lbl->setBuddy(m_pEdit2);
00395     size = m_pEdit2->sizeHint();
00396     m_pEdit2->setFixedHeight(size.height());
00397     m_pEdit2->setMinimumWidth(size.width());
00398     h_lay->addWidget(m_pEdit2);
00399 
00400         // Row 6: Password strength meter
00401         m_pGrid->setRowStretch(10, 12);
00402 
00403         KHBox* const strengthBox = new KHBox(m_pMain);
00404         strengthBox->setSpacing(10);
00405         m_pGrid->addWidget(strengthBox, 11, 0, 1, 3);
00406         QLabel* const passStrengthLabel = new QLabel(strengthBox);
00407         passStrengthLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00408         passStrengthLabel->setText(i18n("Password strength meter:"));
00409         d->m_strengthBar = new QProgressBar(strengthBox);
00410         d->m_strengthBar->setObjectName("PasswordStrengthMeter");
00411         d->m_strengthBar->setRange(0, 100);
00412         d->m_strengthBar->setTextVisible(false);
00413 
00414         const QString strengthBarWhatsThis(i18n("The password strength meter gives an indication of the security "
00415                                                 "of the password you have entered.  To improve the strength of "
00416                                                 "the password, try:\n"
00417                                                 " - using a longer password;\n"
00418                                                 " - using a mixture of upper- and lower-case letters;\n"
00419                                                 " - using numbers or symbols, such as #, as well as letters."));
00420         passStrengthLabel->setWhatsThis(strengthBarWhatsThis);
00421         d->m_strengthBar->setWhatsThis(strengthBarWhatsThis);
00422 
00423         // Row 6: Label saying whether the passwords match
00424         m_pGrid->setRowStretch(12, 12);
00425 
00426         d->m_MatchLabel = new QLabel(m_pMain);
00427         d->m_MatchLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
00428         d->m_MatchLabel->setWordWrap(true);
00429         m_pGrid->addWidget(d->m_MatchLabel, 13, 0, 1, 3);
00430         d->m_MatchLabel->setText(i18n("Passwords do not match"));
00431 
00432 
00433         connect( m_pEdit, SIGNAL(textChanged(const QString&)), SLOT(enableOkBtn()) );
00434         connect( m_pEdit2, SIGNAL(textChanged(const QString&)), SLOT(enableOkBtn()) );
00435         enableOkBtn();
00436     }
00437 
00438     erase();
00439 }
00440 
00441 
00442 K3PasswordDialog::~K3PasswordDialog()
00443 {
00444     delete d;
00445 }
00446 
00447 
00448 void K3PasswordDialog::clearPassword()
00449 {
00450     m_pEdit->erase();
00451 }
00452 
00453 void K3PasswordDialog::setPrompt(const QString &prompt)
00454 {
00455     m_pHelpLbl->setText(prompt);
00456     m_pHelpLbl->setFixedSize(275, m_pHelpLbl->heightForWidth(275));
00457 }
00458 
00459 
00460 QString K3PasswordDialog::prompt() const
00461 
00462 {
00463     return m_pHelpLbl->text();
00464 }
00465 
00466 
00467 void K3PasswordDialog::addLine(const QString &key, const QString &value)
00468 {
00469     if (m_Row > 3)
00470     return;
00471 
00472     QLabel *lbl = new QLabel(key, m_pMain);
00473     lbl->setAlignment(Qt::AlignLeft|Qt::AlignTop);
00474     lbl->setFixedSize(lbl->sizeHint());
00475     m_pGrid->addWidget(lbl, m_Row+2, 0, Qt::AlignLeft);
00476 
00477     lbl = new QLabel(value, m_pMain);
00478     lbl->setAlignment(Qt::AlignTop);
00479     lbl->setWordWrap(true);
00480     lbl->setFixedSize(275, lbl->heightForWidth(275));
00481     m_pGrid->addWidget(lbl, m_Row+2, 2, Qt::AlignLeft);
00482     ++m_Row;
00483 }
00484 
00485 
00486 void K3PasswordDialog::erase()
00487 {
00488     m_pEdit->erase();
00489     m_pEdit->setFocus();
00490     if (m_Type == NewPassword)
00491     m_pEdit2->erase();
00492 }
00493 
00494 
00495 void K3PasswordDialog::accept()
00496 {
00497     if (m_Type == NewPassword) {
00498     if (strcmp(m_pEdit->password(), m_pEdit2->password())) {
00499         KMessageBox::sorry(this, i18n("You entered two different "
00500             "passwords. Please try again."));
00501         erase();
00502         return;
00503     }
00504     if (d->m_strengthBar && d->m_strengthBar->value() < d->passwordStrengthWarningLevel) {
00505         int retVal = KMessageBox::warningContinueCancel(this,
00506         i18n(   "The password you have entered has a low strength. "
00507             "To improve the strength of "
00508             "the password, try:\n"
00509             " - using a longer password;\n"
00510             " - using a mixture of upper- and lower-case letters;\n"
00511             " - using numbers or symbols as well as letters.\n"
00512             "\n"
00513             "Would you like to use this password anyway?"),
00514         i18n("Low Password Strength"));
00515         if (retVal == KMessageBox::Cancel) return;
00516     }
00517     }
00518     if (!checkPassword(m_pEdit->password())) {
00519     erase();
00520     return;
00521     }
00522     KDialog::accept();
00523 }
00524 
00525 
00526 
00527 
00528 void K3PasswordDialog::slotKeep(bool keep)
00529 {
00530     m_Keep = keep;
00531 }
00532 
00533 bool K3PasswordDialog::checkPassword(const char *)
00534 {
00535     return true;
00536 }
00537 
00538 
00539 int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &caption,
00540     const QString &prompt, bool *keep)
00541 {
00542     const bool enableKeep = (keep && *keep);
00543     K3PasswordDialog* const dlg = new K3PasswordDialog(Password, enableKeep,false,parent);
00544     dlg->setWindowTitle(caption);
00545     dlg->setPrompt(prompt);
00546     const int ret = dlg->exec();
00547     if (ret == Accepted) {
00548     password = dlg->password();
00549     if (enableKeep)
00550         *keep = dlg->keep();
00551     }
00552     delete dlg;
00553     return ret;
00554 }
00555 
00556 int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &prompt,
00557     int *keep)
00558 {
00559     int res = K3PasswordDialog::Rejected;
00560     if (keep) {
00561         bool boolkeep = *keep;
00562         res = getPassword(parent, password, i18n("Password Input"), prompt, &boolkeep);
00563         *keep = boolkeep;
00564     }
00565     else {
00566         res = getPassword(parent, password, i18n("Password Input"), prompt);
00567     }
00568     return res;
00569 }
00570 
00571 
00572 int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &caption,
00573     const QString &prompt)
00574 {
00575     K3PasswordDialog* const dlg = new K3PasswordDialog(NewPassword, false,false,parent);
00576     dlg->setWindowTitle(caption);
00577     dlg->setPrompt(prompt);
00578     const int ret = dlg->exec();
00579     if (ret == Accepted)
00580     password = dlg->password();
00581     delete dlg;
00582     return ret;
00583 }
00584 
00585 int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &prompt)
00586 {
00587     return getNewPassword(parent, password, i18n("Password Input"), prompt);
00588 }
00589 
00590 
00591 // static
00592 void K3PasswordDialog::disableCoreDumps()
00593 {
00594     struct rlimit rlim;
00595     rlim.rlim_cur = rlim.rlim_max = 0;
00596     setrlimit(RLIMIT_CORE, &rlim);
00597 }
00598 
00599 
00600 void K3PasswordDialog::enableOkBtn()
00601 {
00602     if (m_Type == NewPassword) {
00603       const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0
00604                    && (d->allowEmptyPasswords || m_pEdit->password()[0]);
00605 
00606       const QString pass(m_pEdit->password());
00607 
00608       const int minPasswordLength = minimumPasswordLength();
00609 
00610       if ((int) pass.length() < minPasswordLength) {
00611           enableButtonOk(false);
00612       } else {
00613           enableButtonOk( match );
00614       }
00615 
00616       if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) {
00617           d->m_MatchLabel->setText( i18n("Password is empty") );
00618       } else {
00619           if ((int) pass.length() < minPasswordLength) {
00620               d->m_MatchLabel->setText(i18np("Password must be at least 1 character long", "Password must be at least %1 characters long", minPasswordLength));
00621           } else {
00622               d->m_MatchLabel->setText( match? i18n("Passwords match")
00623                                               :i18n("Passwords do not match") );
00624           }
00625       }
00626 
00627       // Password strength calculator
00628       // Based on code in the Master Password dialog in Firefox
00629       // (pref-masterpass.js)
00630       // Original code triple-licensed under the MPL, GPL, and LGPL
00631       // so is license-compatible with this file
00632 
00633       const double lengthFactor = d->reasonablePasswordLength / 8.0;
00634 
00635       
00636       int pwlength = (int) (pass.length() / lengthFactor);
00637       if (pwlength > 5) pwlength = 5;
00638 
00639       const QRegExp numRxp("[0-9]", Qt::CaseSensitive, QRegExp::RegExp);
00640       int numeric = (int) (pass.count(numRxp) / lengthFactor);
00641       if (numeric > 3) numeric = 3;
00642 
00643       const QRegExp symbRxp("\\W", Qt::CaseInsensitive, QRegExp::RegExp);
00644       int numsymbols = (int) (pass.count(symbRxp) / lengthFactor);
00645       if (numsymbols > 3) numsymbols = 3;
00646 
00647       const QRegExp upperRxp("[A-Z]", Qt::CaseSensitive, QRegExp::RegExp);
00648       int upper = (int) (pass.count(upperRxp) / lengthFactor);
00649       if (upper > 3) upper = 3;
00650 
00651       int pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);
00652 
00653       if ( pwstrength < 0 ) {
00654           pwstrength = 0;
00655       }
00656   
00657       if ( pwstrength > 100 ) {
00658           pwstrength = 100;
00659       }
00660       d->m_strengthBar->setValue(pwstrength);
00661 
00662    }
00663 }
00664 
00665 
00666 void K3PasswordDialog::setAllowEmptyPasswords(bool allowed) {
00667     d->allowEmptyPasswords = allowed;
00668     enableOkBtn();
00669 }
00670 
00671 
00672 bool K3PasswordDialog::allowEmptyPasswords() const {
00673     return d->allowEmptyPasswords;
00674 }
00675 
00676 void K3PasswordDialog::setMinimumPasswordLength(int minLength) {
00677     d->minimumPasswordLength = minLength;
00678     enableOkBtn();
00679 }
00680 
00681 int K3PasswordDialog::minimumPasswordLength() const {
00682     return d->minimumPasswordLength;
00683 }
00684 
00685 void K3PasswordDialog::setMaximumPasswordLength(int maxLength) {
00686 
00687     if (maxLength < 0) maxLength = 0;
00688     if (maxLength >= K3PasswordEdit::PassLen) maxLength = K3PasswordEdit::PassLen - 1;
00689 
00690     d->maximumPasswordLength = maxLength;
00691 
00692     m_pEdit->setMaxPasswordLength(maxLength);
00693     if (m_pEdit2) m_pEdit2->setMaxPasswordLength(maxLength);
00694 
00695 }
00696 
00697 int K3PasswordDialog::maximumPasswordLength() const {
00698     return d->maximumPasswordLength;
00699 }
00700 
00701 // reasonable password length code contributed by Steffen Mthing
00702 
00703 void K3PasswordDialog::setReasonablePasswordLength(int reasonableLength) {
00704 
00705     if (reasonableLength < 1) reasonableLength = 1;
00706     if (reasonableLength >= maximumPasswordLength()) reasonableLength = maximumPasswordLength();
00707 
00708     d->reasonablePasswordLength = reasonableLength;
00709 
00710 }
00711 
00712 int K3PasswordDialog::reasonablePasswordLength() const {
00713   return d->reasonablePasswordLength;
00714 }
00715 
00716 
00717 void K3PasswordDialog::setPasswordStrengthWarningLevel(int warningLevel) {
00718     if (warningLevel < 0) warningLevel = 0;
00719     if (warningLevel > 99) warningLevel = 99;
00720     d->passwordStrengthWarningLevel = warningLevel;
00721 }
00722 
00723 int K3PasswordDialog::passwordStrengthWarningLevel() const {
00724     return d->passwordStrengthWarningLevel;
00725 }
00726 
00727 const char *K3PasswordDialog::password() const
00728 {
00729     return m_pEdit->password();
00730 }
00731 
00732 bool K3PasswordDialog::keep() const
00733 {
00734     return m_Keep;
00735 }
00736 
00737 #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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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