• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDE3Support

  • kde3support
  • kdeui
k3passworddialog.cpp
Go to the documentation of this file.
1// vi: ts=8 sts=4 sw=4
2/* This file is part of the KDE libraries
3 Copyright (C) 1998 Pietro Iglio <iglio@fub.it>
4 Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
5 Copyright (C) 2004,2005 Andrew Coles <andrew_coles@yahoo.co.uk>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "k3passworddialog.h"
23
24#include <sys/time.h>
25#include <sys/resource.h>
26
27#include <QtCore/QCoreApplication>
28#include <QtCore/QRegExp>
29#include <QtCore/QSize>
30#include <QtCore/QString>
31#include <QtGui/QCheckBox>
32#include <QtGui/QLabel>
33#include <QtGui/QLayout>
34#include <QtGui/QKeyEvent>
35#include <QtGui/QProgressBar>
36#include <QtGui/QWidget>
37
38#include <Q3PtrDict>
39
40#include <kconfig.h>
41#include <kglobal.h>
42#include <khbox.h>
43#include <kiconloader.h>
44#include <klocale.h>
45#include <kmessagebox.h>
46
47#include <kconfiggroup.h>
48
49/*
50 * Password line editor.
51 */
52
53// BCI: Add a real d-pointer and put the int into that
54
55static Q3PtrDict<int>* d_ptr = 0;
56
57static void cleanup_d_ptr() {
58 delete d_ptr;
59}
60
61static int * ourMaxLength( const K3PasswordEdit* const e ) {
62 if ( !d_ptr ) {
63 d_ptr = new Q3PtrDict<int>;
64 d_ptr->setAutoDelete(true);
65 qAddPostRoutine( cleanup_d_ptr );
66 }
67 int* ret = d_ptr->find( (void*) e );
68 if ( ! ret ) {
69 ret = new int;
70 d_ptr->replace( (void*) e, ret );
71 }
72 return ret;
73}
74
75static void delete_d( const K3PasswordEdit* const e ) {
76 if ( d_ptr )
77 d_ptr->remove( (void*) e );
78}
79
80const int K3PasswordEdit::PassLen = 200;
81
82class K3PasswordDialog::K3PasswordDialogPrivate
83{
84 public:
85 K3PasswordDialogPrivate()
86 : m_MatchLabel( 0 ), allowEmptyPasswords( false ),
87 minimumPasswordLength(0), maximumPasswordLength(K3PasswordEdit::PassLen - 1),
88 passwordStrengthWarningLevel(1), m_strengthBar(0),
89 reasonablePasswordLength(8)
90 {}
91 QLabel *m_MatchLabel;
92 QString iconName;
93 bool allowEmptyPasswords;
94 int minimumPasswordLength;
95 int maximumPasswordLength;
96 int passwordStrengthWarningLevel;
97 QProgressBar* m_strengthBar;
98 int reasonablePasswordLength;
99};
100
101
102K3PasswordEdit::K3PasswordEdit(QWidget *parent) : QLineEdit(parent)
103{
104 init();
105
106 KConfigGroup cg(KGlobal::config(), "Passwords");
107
108 const QString val = cg.readEntry("EchoMode", "OneStar");
109 if (val == "ThreeStars")
110 m_EchoMode = ThreeStars;
111 else if (val == "NoEcho")
112 m_EchoMode = NoEcho;
113 else
114 m_EchoMode = OneStar;
115
116}
117
118K3PasswordEdit::K3PasswordEdit(EchoModes echoMode, QWidget *parent)
119 : QLineEdit(parent), m_EchoMode(echoMode)
120{
121 init();
122}
123
124K3PasswordEdit::K3PasswordEdit(EchoMode echoMode, QWidget *parent)
125 : QLineEdit(parent)
126 , m_EchoMode( echoMode == QLineEdit::NoEcho ? NoEcho : OneStar )
127{
128 init();
129}
130
131void K3PasswordEdit::init()
132{
133 setEchoMode(QLineEdit::Password); // Just in case
134 setAcceptDrops(false);
135 int* t = ourMaxLength(this);
136 *t = (PassLen - 1); // the internal max length
137 m_Password = new char[PassLen];
138 m_Password[0] = '\000';
139 m_Length = 0;
140}
141
142K3PasswordEdit::~K3PasswordEdit()
143{
144 memset(m_Password, 0, PassLen * sizeof(char));
145 delete[] m_Password;
146 delete_d(this);
147}
148
149const char *K3PasswordEdit::password() const
150{
151 return m_Password;
152}
153
154void K3PasswordEdit::insert(const QString &txt)
155{
156 const QByteArray localTxt = txt.toLocal8Bit();
157 const unsigned int lim = localTxt.length();
158 const int m_MaxLength = maxPasswordLength();
159 for(unsigned int i=0; i < lim; ++i)
160 {
161 const unsigned char ke = localTxt[i];
162 if (m_Length < m_MaxLength)
163 {
164 m_Password[m_Length] = ke;
165 m_Password[++m_Length] = '\000';
166 }
167 }
168 showPass();
169}
170
171void K3PasswordEdit::erase()
172{
173 m_Length = 0;
174 memset(m_Password, 0, PassLen * sizeof(char));
175 setText("");
176}
177
178void K3PasswordEdit::focusInEvent(QFocusEvent *e)
179{
180 const QString txt = text();
181 setUpdatesEnabled(false);
182 QLineEdit::focusInEvent(e);
183 setUpdatesEnabled(true);
184 setText(txt);
185}
186
187
188void K3PasswordEdit::keyPressEvent(QKeyEvent *e)
189{
190 switch (e->key()) {
191 case Qt::Key_Return:
192 case Qt::Key_Enter:
193 case Qt::Key_Escape:
194 e->ignore();
195 break;
196 case Qt::Key_Backspace:
197 case Qt::Key_Delete:
198 case 0x7f: // Delete
199 if (e->modifiers() & (Qt::ControlModifier | Qt::AltModifier))
200 e->ignore();
201 else if (m_Length) {
202 m_Password[--m_Length] = '\000';
203 showPass();
204 }
205 break;
206 default:
207 const unsigned char ke = e->text().toLocal8Bit()[0];
208 if (ke >= 32) {
209 insert(e->text());
210 } else
211 e->ignore();
212 break;
213 }
214}
215
216bool K3PasswordEdit::event(QEvent *e) {
217 switch(e->type()) {
218
219 case QEvent::MouseButtonPress:
220 case QEvent::MouseButtonRelease:
221 case QEvent::MouseButtonDblClick:
222 case QEvent::MouseMove:
223 return true; //Ignore
224 case QEvent::InputMethod:
225 {
226 QInputMethodEvent* const ie = (QInputMethodEvent*) e;
227 if (!ie->commitString().isNull())
228 insert( ie->commitString() );
229 return true;
230 }
231
232 case QEvent::ShortcutOverride:
233 {
234 QKeyEvent* const k = (QKeyEvent*) e;
235 switch (k->key()) {
236 case Qt::Key_U:
237 if (k->modifiers() & Qt::ControlModifier) {
238 m_Length = 0;
239 m_Password[m_Length] = '\000';
240 showPass();
241 }
242 }
243 return true; // stop bubbling
244 }
245
246 default:
247 // Do nothing
248 break;
249 }
250 return QLineEdit::event(e);
251}
252
253void K3PasswordEdit::showPass()
254{
255 QString tmp;
256
257 switch (m_EchoMode) {
258 case OneStar:
259 tmp.fill('*', m_Length);
260 setText(tmp);
261 break;
262 case ThreeStars:
263 tmp.fill('*', m_Length*3);
264 setText(tmp);
265 break;
266 case NoEcho: default:
267 emit textChanged(QString()); //To update the password comparison if need be.
268 break;
269 }
270}
271
272void K3PasswordEdit::setMaxPasswordLength(int newLength)
273{
274 if (newLength >= PassLen) newLength = PassLen - 1; // belt and braces
275 if (newLength < 0) newLength = 0;
276 int* t = ourMaxLength(this);
277 *t = newLength;
278 while (m_Length > newLength) {
279 m_Password[m_Length] = '\000';
280 --m_Length;
281 }
282 showPass();
283}
284
285int K3PasswordEdit::maxPasswordLength() const
286{
287 return *(ourMaxLength(this));
288}
289/*
290 * Password dialog.
291 */
292
293K3PasswordDialog::K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn,
294 QWidget *parent)
295 : KDialog(parent, Qt::Dialog)
296 , m_Keep(enableKeep? 1 : 0), m_Type(type), d(new K3PasswordDialogPrivate)
297{
298 setButtons( Ok|Cancel|extraBttn );
299 setModal( true );
300 setDefaultButton( Ok );
301 d->iconName = "password";
302 init();
303}
304
305K3PasswordDialog::K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn, const QString& icon,
306 QWidget *parent)
307 : KDialog(parent, Qt::Dialog)
308 , m_Keep(enableKeep? 1 : 0), m_Type(type), d(new K3PasswordDialogPrivate)
309{
310 setButtons( Ok|Cancel|extraBttn );
311 setModal( true );
312 setDefaultButton( Ok );
313 if ( icon.trimmed().isEmpty() )
314 d->iconName = "password";
315 else
316 d->iconName = icon;
317 init();
318}
319
320
321void K3PasswordDialog::init()
322{
323 m_Row = 0;
324
325 KConfigGroup cg(KGlobal::config(), "Passwords");
326 if (m_Keep && cg.readEntry("Keep", false))
327 ++m_Keep;
328
329 m_pMain = new QWidget(this);
330 setMainWidget(m_pMain);
331 m_pGrid = new QGridLayout(m_pMain);
332 m_pGrid->setMargin(0);
333 m_pGrid->setSpacing(0);
334
335 // Row 1: pixmap + prompt
336 QLabel *lbl;
337 const QPixmap pix( KIconLoader::global()->loadIcon( d->iconName, KIconLoader::NoGroup, KIconLoader::SizeHuge, 0, QStringList(), 0, true));
338 if (!pix.isNull()) {
339 lbl = new QLabel(m_pMain);
340 lbl->setPixmap(pix);
341 lbl->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
342 lbl->setFixedSize(lbl->sizeHint());
343 m_pGrid->addWidget(lbl, 0, 0, Qt::AlignCenter);
344 }
345
346 m_pHelpLbl = new QLabel(m_pMain);
347 m_pHelpLbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
348 m_pHelpLbl->setWordWrap(true);
349 m_pGrid->addWidget(m_pHelpLbl, 0, 2, Qt::AlignLeft);
350 m_pGrid->setRowStretch(1, 12);
351
352 // Row 2+: space for 4 extra info lines
353 m_pGrid->setRowStretch(6, 12);
354
355 // Row 3: Password editor #1
356 lbl = new QLabel(m_pMain);
357 lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
358 lbl->setText(i18n("&Password:"));
359 lbl->setFixedSize(lbl->sizeHint());
360 m_pGrid->addWidget(lbl, 7, 0, Qt::AlignLeft);
361
362 QHBoxLayout *h_lay = new QHBoxLayout();
363 m_pGrid->addLayout(h_lay, 7, 2);
364 m_pEdit = new K3PasswordEdit(m_pMain);
365 m_pEdit2 = 0;
366 lbl->setBuddy(m_pEdit);
367 QSize size = m_pEdit->sizeHint();
368 m_pEdit->setFixedHeight(size.height());
369 m_pEdit->setMinimumWidth(size.width());
370 h_lay->addWidget(m_pEdit);
371
372 // Row 4: Password editor #2 or keep password checkbox
373
374 if ((m_Type == Password) && m_Keep) {
375 m_pGrid->setRowStretch(8, 12);
376 QCheckBox* const cb = new QCheckBox(i18n("&Keep password"), m_pMain);
377 cb->setFixedSize(cb->sizeHint());
378 if (m_Keep > 1)
379 cb->setChecked(true);
380 else
381 m_Keep = 0;
382 connect(cb, SIGNAL(toggled(bool)), SLOT(slotKeep(bool)));
383 m_pGrid->addWidget(cb, 9, 2, Qt::AlignLeft|Qt::AlignVCenter);
384 } else if (m_Type == NewPassword) {
385 lbl = new QLabel(m_pMain);
386 lbl->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
387 lbl->setText(i18n("&Verify:"));
388 lbl->setFixedSize(lbl->sizeHint());
389 m_pGrid->addWidget(lbl, 9, 0, Qt::AlignLeft);
390
391 h_lay = new QHBoxLayout();
392 m_pGrid->addLayout(h_lay, 9, 2);
393 m_pEdit2 = new K3PasswordEdit(m_pMain);
394 lbl->setBuddy(m_pEdit2);
395 size = m_pEdit2->sizeHint();
396 m_pEdit2->setFixedHeight(size.height());
397 m_pEdit2->setMinimumWidth(size.width());
398 h_lay->addWidget(m_pEdit2);
399
400 // Row 6: Password strength meter
401 m_pGrid->setRowStretch(10, 12);
402
403 KHBox* const strengthBox = new KHBox(m_pMain);
404 strengthBox->setSpacing(10);
405 m_pGrid->addWidget(strengthBox, 11, 0, 1, 3);
406 QLabel* const passStrengthLabel = new QLabel(strengthBox);
407 passStrengthLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
408 passStrengthLabel->setText(i18n("Password strength meter:"));
409 d->m_strengthBar = new QProgressBar(strengthBox);
410 d->m_strengthBar->setObjectName("PasswordStrengthMeter");
411 d->m_strengthBar->setRange(0, 100);
412 d->m_strengthBar->setTextVisible(false);
413
414 const QString strengthBarWhatsThis(i18n("The password strength meter gives an indication of the security "
415 "of the password you have entered. To improve the strength of "
416 "the password, try:\n"
417 " - using a longer password;\n"
418 " - using a mixture of upper- and lower-case letters;\n"
419 " - using numbers or symbols, such as #, as well as letters."));
420 passStrengthLabel->setWhatsThis(strengthBarWhatsThis);
421 d->m_strengthBar->setWhatsThis(strengthBarWhatsThis);
422
423 // Row 6: Label saying whether the passwords match
424 m_pGrid->setRowStretch(12, 12);
425
426 d->m_MatchLabel = new QLabel(m_pMain);
427 d->m_MatchLabel->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
428 d->m_MatchLabel->setWordWrap(true);
429 m_pGrid->addWidget(d->m_MatchLabel, 13, 0, 1, 3);
430 d->m_MatchLabel->setText(i18n("Passwords do not match"));
431
432
433 connect( m_pEdit, SIGNAL(textChanged(QString)), SLOT(enableOkBtn()) );
434 connect( m_pEdit2, SIGNAL(textChanged(QString)), SLOT(enableOkBtn()) );
435 enableOkBtn();
436 }
437
438 erase();
439}
440
441
442K3PasswordDialog::~K3PasswordDialog()
443{
444 delete d;
445}
446
447
448void K3PasswordDialog::clearPassword()
449{
450 m_pEdit->erase();
451}
452
453void K3PasswordDialog::setPrompt(const QString &prompt)
454{
455 m_pHelpLbl->setText(prompt);
456 m_pHelpLbl->setFixedSize(275, m_pHelpLbl->heightForWidth(275));
457}
458
459
460QString K3PasswordDialog::prompt() const
461
462{
463 return m_pHelpLbl->text();
464}
465
466
467void K3PasswordDialog::addLine(const QString &key, const QString &value)
468{
469 if (m_Row > 3)
470 return;
471
472 QLabel *lbl = new QLabel(key, m_pMain);
473 lbl->setAlignment(Qt::AlignLeft|Qt::AlignTop);
474 lbl->setFixedSize(lbl->sizeHint());
475 m_pGrid->addWidget(lbl, m_Row+2, 0, Qt::AlignLeft);
476
477 lbl = new QLabel(value, m_pMain);
478 lbl->setAlignment(Qt::AlignTop);
479 lbl->setWordWrap(true);
480 lbl->setFixedSize(275, lbl->heightForWidth(275));
481 m_pGrid->addWidget(lbl, m_Row+2, 2, Qt::AlignLeft);
482 ++m_Row;
483}
484
485
486void K3PasswordDialog::erase()
487{
488 m_pEdit->erase();
489 m_pEdit->setFocus();
490 if (m_Type == NewPassword)
491 m_pEdit2->erase();
492}
493
494
495void K3PasswordDialog::accept()
496{
497 if (m_Type == NewPassword) {
498 if (strcmp(m_pEdit->password(), m_pEdit2->password())) {
499 KMessageBox::sorry(this, i18n("You entered two different "
500 "passwords. Please try again."));
501 erase();
502 return;
503 }
504 if (d->m_strengthBar && d->m_strengthBar->value() < d->passwordStrengthWarningLevel) {
505 int retVal = KMessageBox::warningContinueCancel(this,
506 i18n( "The password you have entered has a low strength. "
507 "To improve the strength of "
508 "the password, try:\n"
509 " - using a longer password;\n"
510 " - using a mixture of upper- and lower-case letters;\n"
511 " - using numbers or symbols as well as letters.\n"
512 "\n"
513 "Would you like to use this password anyway?"),
514 i18n("Low Password Strength"));
515 if (retVal == KMessageBox::Cancel) return;
516 }
517 }
518 if (!checkPassword(m_pEdit->password())) {
519 erase();
520 return;
521 }
522 KDialog::accept();
523}
524
525
526
527
528void K3PasswordDialog::slotKeep(bool keep)
529{
530 m_Keep = keep;
531}
532
533bool K3PasswordDialog::checkPassword(const char *)
534{
535 return true;
536}
537
538
539int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &caption,
540 const QString &prompt, bool *keep)
541{
542 const bool enableKeep = (keep && *keep);
543 K3PasswordDialog* const dlg = new K3PasswordDialog(Password, enableKeep,KDialog::None,parent);
544 dlg->setWindowTitle(caption);
545 dlg->setPrompt(prompt);
546 const int ret = dlg->exec();
547 if (ret == Accepted) {
548 password = dlg->password();
549 if (enableKeep)
550 *keep = dlg->keep();
551 }
552 delete dlg;
553 return ret;
554}
555
556int K3PasswordDialog::getPassword(QWidget *parent, QByteArray &password, const QString &prompt,
557 int *keep)
558{
559 int res = K3PasswordDialog::Rejected;
560 if (keep) {
561 bool boolkeep = *keep;
562 res = getPassword(parent, password, i18n("Password Input"), prompt, &boolkeep);
563 *keep = boolkeep;
564 }
565 else {
566 res = getPassword(parent, password, i18n("Password Input"), prompt);
567 }
568 return res;
569}
570
571
572int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &caption,
573 const QString &prompt)
574{
575 K3PasswordDialog* const dlg = new K3PasswordDialog(NewPassword, false,KDialog::None,parent);
576 dlg->setWindowTitle(caption);
577 dlg->setPrompt(prompt);
578 const int ret = dlg->exec();
579 if (ret == Accepted)
580 password = dlg->password();
581 delete dlg;
582 return ret;
583}
584
585int K3PasswordDialog::getNewPassword(QWidget *parent, QByteArray &password, const QString &prompt)
586{
587 return getNewPassword(parent, password, i18n("Password Input"), prompt);
588}
589
590
591// static
592void K3PasswordDialog::disableCoreDumps()
593{
594 struct rlimit rlim;
595 rlim.rlim_cur = rlim.rlim_max = 0;
596 setrlimit(RLIMIT_CORE, &rlim);
597}
598
599
600void K3PasswordDialog::enableOkBtn()
601{
602 if (m_Type == NewPassword) {
603 const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0
604 && (d->allowEmptyPasswords || m_pEdit->password()[0]);
605
606 const QString pass(m_pEdit->password());
607
608 const int minPasswordLength = minimumPasswordLength();
609
610 if ((int) pass.length() < minPasswordLength) {
611 enableButtonOk(false);
612 } else {
613 enableButtonOk( match );
614 }
615
616 if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) {
617 d->m_MatchLabel->setText( i18n("Password is empty") );
618 } else {
619 if ((int) pass.length() < minPasswordLength) {
620 d->m_MatchLabel->setText(i18np("Password must be at least 1 character long", "Password must be at least %1 characters long", minPasswordLength));
621 } else {
622 d->m_MatchLabel->setText( match? i18n("Passwords match")
623 :i18n("Passwords do not match") );
624 }
625 }
626
627 // Password strength calculator
628 // Based on code in the Master Password dialog in Firefox
629 // (pref-masterpass.js)
630 // Original code triple-licensed under the MPL, GPL, and LGPL
631 // so is license-compatible with this file
632
633 const double lengthFactor = d->reasonablePasswordLength / 8.0;
634
635
636 int pwlength = (int) (pass.length() / lengthFactor);
637 if (pwlength > 5) pwlength = 5;
638
639 const QRegExp numRxp("[0-9]", Qt::CaseSensitive, QRegExp::RegExp);
640 int numeric = (int) (pass.count(numRxp) / lengthFactor);
641 if (numeric > 3) numeric = 3;
642
643 const QRegExp symbRxp("\\W", Qt::CaseInsensitive, QRegExp::RegExp);
644 int numsymbols = (int) (pass.count(symbRxp) / lengthFactor);
645 if (numsymbols > 3) numsymbols = 3;
646
647 const QRegExp upperRxp("[A-Z]", Qt::CaseSensitive, QRegExp::RegExp);
648 int upper = (int) (pass.count(upperRxp) / lengthFactor);
649 if (upper > 3) upper = 3;
650
651 int pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);
652
653 if ( pwstrength < 0 ) {
654 pwstrength = 0;
655 }
656
657 if ( pwstrength > 100 ) {
658 pwstrength = 100;
659 }
660 d->m_strengthBar->setValue(pwstrength);
661
662 }
663}
664
665
666void K3PasswordDialog::setAllowEmptyPasswords(bool allowed) {
667 d->allowEmptyPasswords = allowed;
668 enableOkBtn();
669}
670
671
672bool K3PasswordDialog::allowEmptyPasswords() const {
673 return d->allowEmptyPasswords;
674}
675
676void K3PasswordDialog::setMinimumPasswordLength(int minLength) {
677 d->minimumPasswordLength = minLength;
678 enableOkBtn();
679}
680
681int K3PasswordDialog::minimumPasswordLength() const {
682 return d->minimumPasswordLength;
683}
684
685void K3PasswordDialog::setMaximumPasswordLength(int maxLength) {
686
687 if (maxLength < 0) maxLength = 0;
688 if (maxLength >= K3PasswordEdit::PassLen) maxLength = K3PasswordEdit::PassLen - 1;
689
690 d->maximumPasswordLength = maxLength;
691
692 m_pEdit->setMaxPasswordLength(maxLength);
693 if (m_pEdit2) m_pEdit2->setMaxPasswordLength(maxLength);
694
695}
696
697int K3PasswordDialog::maximumPasswordLength() const {
698 return d->maximumPasswordLength;
699}
700
701// reasonable password length code contributed by Steffen Mthing
702
703void K3PasswordDialog::setReasonablePasswordLength(int reasonableLength) {
704
705 if (reasonableLength < 1) reasonableLength = 1;
706 if (reasonableLength >= maximumPasswordLength()) reasonableLength = maximumPasswordLength();
707
708 d->reasonablePasswordLength = reasonableLength;
709
710}
711
712int K3PasswordDialog::reasonablePasswordLength() const {
713 return d->reasonablePasswordLength;
714}
715
716
717void K3PasswordDialog::setPasswordStrengthWarningLevel(int warningLevel) {
718 if (warningLevel < 0) warningLevel = 0;
719 if (warningLevel > 99) warningLevel = 99;
720 d->passwordStrengthWarningLevel = warningLevel;
721}
722
723int K3PasswordDialog::passwordStrengthWarningLevel() const {
724 return d->passwordStrengthWarningLevel;
725}
726
727const char *K3PasswordDialog::password() const
728{
729 return m_pEdit->password();
730}
731
732bool K3PasswordDialog::keep() const
733{
734 return m_Keep;
735}
736
737#include "k3passworddialog.moc"
K3PasswordDialog
A password input dialog.
Definition: k3passworddialog.h:161
K3PasswordDialog::disableCoreDumps
static void disableCoreDumps()
Static helper function that disables core dumps.
Definition: k3passworddialog.cpp:592
K3PasswordDialog::keep
bool keep() const
Returns true if the user wants to keep the password.
Definition: k3passworddialog.cpp:732
K3PasswordDialog::getNewPassword
static int getNewPassword(QWidget *parent, QByteArray &password, const QString &caption, const QString &prompt)
Pops up the dialog, asks the user for a password and returns it.
Definition: k3passworddialog.cpp:572
K3PasswordDialog::maximumPasswordLength
int maximumPasswordLength() const
Maximum acceptable password length.
Definition: k3passworddialog.cpp:697
K3PasswordDialog::setAllowEmptyPasswords
void setAllowEmptyPasswords(bool allowed)
Allow empty passwords? - Default: false.
Definition: k3passworddialog.cpp:666
K3PasswordDialog::setPrompt
void setPrompt(const QString &prompt)
Sets the password prompt.
Definition: k3passworddialog.cpp:453
K3PasswordDialog::Types
Types
This enum distinguishes the two operation modes of this dialog:
Definition: k3passworddialog.h:168
K3PasswordDialog::NewPassword
@ NewPassword
The user is asked to enter a password and to confirm it a second time.
Definition: k3passworddialog.h:179
K3PasswordDialog::Password
@ Password
The user is asked to enter a password.
Definition: k3passworddialog.h:172
K3PasswordDialog::slotKeep
void slotKeep(bool)
Definition: k3passworddialog.cpp:528
K3PasswordDialog::setPasswordStrengthWarningLevel
void setPasswordStrengthWarningLevel(int warningLevel)
Set the password strength level below which a warning is given Value is in the range 0 to 99.
Definition: k3passworddialog.cpp:717
K3PasswordDialog::reasonablePasswordLength
int reasonablePasswordLength() const
Password length that is expected to be reasonably safe.
Definition: k3passworddialog.cpp:712
K3PasswordDialog::getPassword
static int getPassword(QWidget *parent, QByteArray &password, const QString &caption, const QString &prompt, bool *keep=0L)
Pops up the dialog, asks the user for a password, and returns it.
Definition: k3passworddialog.cpp:539
K3PasswordDialog::K3PasswordDialog
K3PasswordDialog(Types type, bool enableKeep, ButtonCodes extraBttn, QWidget *parent=0)
Constructs a password dialog.
Definition: k3passworddialog.cpp:293
K3PasswordDialog::minimumPasswordLength
int minimumPasswordLength() const
Minimum acceptable password length.
Definition: k3passworddialog.cpp:681
K3PasswordDialog::accept
virtual void accept()
Definition: k3passworddialog.cpp:495
K3PasswordDialog::passwordStrengthWarningLevel
int passwordStrengthWarningLevel() const
Password strength level below which a warning is given.
Definition: k3passworddialog.cpp:723
K3PasswordDialog::clearPassword
void clearPassword()
Clears the password input field.
Definition: k3passworddialog.cpp:448
K3PasswordDialog::prompt
QString prompt() const
Returns the password prompt.
Definition: k3passworddialog.cpp:460
K3PasswordDialog::setMinimumPasswordLength
void setMinimumPasswordLength(int minLength)
Minimum acceptable password length.
Definition: k3passworddialog.cpp:676
K3PasswordDialog::allowEmptyPasswords
bool allowEmptyPasswords() const
Allow empty passwords?
Definition: k3passworddialog.cpp:672
K3PasswordDialog::checkPassword
virtual bool checkPassword(const char *password)
Virtual function that can be overridden to provide password checking in derived classes.
Definition: k3passworddialog.cpp:533
K3PasswordDialog::addLine
void addLine(const QString &key, const QString &value)
Adds a line of information to the dialog.
Definition: k3passworddialog.cpp:467
K3PasswordDialog::setReasonablePasswordLength
void setReasonablePasswordLength(int reasonableLength)
Password length that is expected to be reasonably safe.
Definition: k3passworddialog.cpp:703
K3PasswordDialog::~K3PasswordDialog
virtual ~K3PasswordDialog()
Destructs the password dialog.
Definition: k3passworddialog.cpp:442
K3PasswordDialog::password
const char * password() const
Returns the password entered.
Definition: k3passworddialog.cpp:727
K3PasswordDialog::setMaximumPasswordLength
void setMaximumPasswordLength(int maxLength)
Maximum acceptable password length.
Definition: k3passworddialog.cpp:685
K3PasswordEdit
A safe password input widget.
Definition: k3passworddialog.h:43
K3PasswordEdit::event
virtual bool event(QEvent *e)
Definition: k3passworddialog.cpp:216
K3PasswordEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: k3passworddialog.cpp:188
K3PasswordEdit::K3PasswordEdit
K3PasswordEdit(QWidget *parent=0)
Constructs a password input widget using the user's global "echo mode" setting.
Definition: k3passworddialog.cpp:102
K3PasswordEdit::EchoModes
EchoModes
Definition: k3passworddialog.h:47
K3PasswordEdit::ThreeStars
@ ThreeStars
Definition: k3passworddialog.h:47
K3PasswordEdit::OneStar
@ OneStar
Definition: k3passworddialog.h:47
K3PasswordEdit::NoEcho
@ NoEcho
Definition: k3passworddialog.h:47
K3PasswordEdit::PassLen
static const int PassLen
Definition: k3passworddialog.h:83
K3PasswordEdit::password
const char * password() const
Returns the password.
Definition: k3passworddialog.cpp:149
K3PasswordEdit::maxPasswordLength
int maxPasswordLength() const
Returns the current maximum password length.
Definition: k3passworddialog.cpp:285
K3PasswordEdit::~K3PasswordEdit
~K3PasswordEdit()
Destructs the widget.
Definition: k3passworddialog.cpp:142
K3PasswordEdit::setMaxPasswordLength
void setMaxPasswordLength(int newLength)
Set the current maximum password length.
Definition: k3passworddialog.cpp:272
K3PasswordEdit::erase
void erase()
Erases the current password.
Definition: k3passworddialog.cpp:171
K3PasswordEdit::focusInEvent
virtual void focusInEvent(QFocusEvent *e)
Definition: k3passworddialog.cpp:178
K3PasswordEdit::insert
virtual void insert(const QString &)
Reimplementation.
Definition: k3passworddialog.cpp:154
KConfigGroup
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KDialog
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
KDialog::enableButtonOk
void enableButtonOk(bool state)
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
KDialog::None
None
KDialog::Ok
Ok
KDialog::Cancel
Cancel
KDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
KHBox
KHBox::setSpacing
void setSpacing(int space)
KIconLoader::NoGroup
NoGroup
KIconLoader::global
static KIconLoader * global()
KIconLoader::SizeHuge
SizeHuge
KMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const KGuiItem &buttonCancel=KStandardGuiItem::cancel(), const QString &dontAskAgainName=QString(), Options options=Notify)
KMessageBox::Cancel
Cancel
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
QEvent
QLabel
QLineEdit
QWidget
cleanup_d_ptr
static void cleanup_d_ptr()
Definition: k3passworddialog.cpp:57
ourMaxLength
static int * ourMaxLength(const K3PasswordEdit *const e)
Definition: k3passworddialog.cpp:61
d_ptr
static Q3PtrDict< int > * d_ptr
Definition: k3passworddialog.cpp:55
delete_d
static void delete_d(const K3PasswordEdit *const e)
Definition: k3passworddialog.cpp:75
k3passworddialog.h
kconfig.h
kconfiggroup.h
kglobal.h
khbox.h
kiconloader.h
klocale.h
i18n
QString i18n(const char *text)
i18np
QString i18np(const char *sing, const char *plur, const A1 &a1)
kmessagebox.h
caption
QString caption()
KGlobal::config
KSharedConfigPtr config()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal