void KNewPasswordWidget::setMaximumPasswordLength(int maxLength) { if (maxLength < minimumPasswordLength()) { maxLength = minimumPasswordLength(); } d->ui.linePassword->setMaxLength(maxLength); d->ui.lineVerifyPassword->setMaxLength(maxLength); }
void K3PasswordDialog::enableOkBtn() { if (m_Type == NewPassword) { const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0 && (d->allowEmptyPasswords || m_pEdit->password()[0]); const QString pass(m_pEdit->password()); const int minPasswordLength = minimumPasswordLength(); if ((int) pass.length() < minPasswordLength) { enableButtonOk(false); } else { enableButtonOk( match ); } if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) { d->m_MatchLabel->setText( i18n("Password is empty") ); } else { if ((int) pass.length() < minPasswordLength) { d->m_MatchLabel->setText(i18np("Password must be at least 1 character long", "Password must be at least %1 characters long", minPasswordLength)); } else { d->m_MatchLabel->setText( match? i18n("Passwords match") :i18n("Passwords do not match") ); } } // Password strength calculator // Based on code in the Master Password dialog in Firefox // (pref-masterpass.js) // Original code triple-licensed under the MPL, GPL, and LGPL // so is license-compatible with this file const double lengthFactor = d->reasonablePasswordLength / 8.0; int pwlength = (int) (pass.length() / lengthFactor); if (pwlength > 5) pwlength = 5; const QRegExp numRxp("[0-9]", Qt::CaseSensitive, QRegExp::RegExp); int numeric = (int) (pass.count(numRxp) / lengthFactor); if (numeric > 3) numeric = 3; const QRegExp symbRxp("\\W", Qt::CaseInsensitive, QRegExp::RegExp); int numsymbols = (int) (pass.count(symbRxp) / lengthFactor); if (numsymbols > 3) numsymbols = 3; const QRegExp upperRxp("[A-Z]", Qt::CaseSensitive, QRegExp::RegExp); int upper = (int) (pass.count(upperRxp) / lengthFactor); if (upper > 3) upper = 3; int pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10); if ( pwstrength < 0 ) { pwstrength = 0; } if ( pwstrength > 100 ) { pwstrength = 100; } d->m_strengthBar->setValue(pwstrength); } }