• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
kpassdlg.cpp
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 #include <unistd.h>
22 
23 #include <tqwidget.h>
24 #include <tqlineedit.h>
25 #include <tqlabel.h>
26 #include <tqlayout.h>
27 #include <tqsize.h>
28 #include <tqevent.h>
29 #include <tqkeycode.h>
30 #include <tqcheckbox.h>
31 #include <tqregexp.h>
32 #include <tqhbox.h>
33 #include <tqwhatsthis.h>
34 #include <tqptrdict.h>
35 #include <tqtimer.h>
36 
37 #include <kglobal.h>
38 #include <kdebug.h>
39 #include <kapplication.h>
40 #include <klocale.h>
41 #include <kiconloader.h>
42 #include <kmessagebox.h>
43 #include <kaboutdialog.h>
44 #include <kconfig.h>
45 #include <kstandarddirs.h>
46 #include <kprogress.h>
47 
48 #include <sys/time.h>
49 #include <sys/resource.h>
50 
51 #include "kpassdlg.h"
52 
53 #include "../kdesu/defaults.h"
54 
55 /*
56  * Password line editor.
57  */
58 
59 // BCI: Add a real d-pointer and put the int into that
60 
61 static TQPtrDict<int>* d_ptr = 0;
62 
63 static void cleanup_d_ptr() {
64  delete d_ptr;
65 }
66 
67 static int * ourMaxLength( const KPasswordEdit* const e ) {
68  if ( !d_ptr ) {
69  d_ptr = new TQPtrDict<int>;
70  d_ptr->setAutoDelete(true);
71  qAddPostRoutine( cleanup_d_ptr );
72  }
73  int* ret = d_ptr->find( (void*) e );
74  if ( ! ret ) {
75  ret = new int;
76  d_ptr->replace( (void*) e, ret );
77  }
78  return ret;
79 }
80 
81 static void delete_d( const KPasswordEdit* const e ) {
82  if ( d_ptr )
83  d_ptr->remove( (void*) e );
84 }
85 
86 const int KPasswordEdit::PassLen = 200;
87 
88 class KPasswordDialog::KPasswordDialogPrivate
89 {
90  public:
91  KPasswordDialogPrivate()
92  : m_MatchLabel( 0 ), iconName( 0 ), allowEmptyPasswords( false ),
93  minimumPasswordLength(0), maximumPasswordLength(KPasswordEdit::PassLen - 1),
94  passwordStrengthWarningLevel(1), m_strengthBar(0),
95  reasonablePasswordLength(8)
96  {}
97  TQLabel *m_MatchLabel;
98  TQString iconName;
99  bool allowEmptyPasswords;
100  int minimumPasswordLength;
101  int maximumPasswordLength;
102  int passwordStrengthWarningLevel;
103  KProgress* m_strengthBar;
104  int reasonablePasswordLength;
105 };
106 
107 
108 KPasswordEdit::KPasswordEdit(TQWidget *parent, const char *name)
109  : TQLineEdit(parent, name)
110 {
111  init();
112 
113  KConfig* const cfg = KGlobal::config();
114  KConfigGroupSaver saver(cfg, "Passwords");
115 
116  const TQString val = cfg->readEntry("EchoMode", "OneStar");
117  if (val == "ThreeStars")
118  m_EchoMode = ThreeStars;
119  else if (val == "NoEcho")
120  m_EchoMode = NoEcho;
121  else
122  m_EchoMode = OneStar;
123 
124  setInputMethodEnabled( true );
125 }
126 
127 KPasswordEdit::KPasswordEdit(TQWidget *parent, const char *name, int echoMode)
128  : TQLineEdit(parent, name), m_EchoMode(echoMode)
129 {
130  init();
131 }
132 
133 KPasswordEdit::KPasswordEdit(EchoModes echoMode, TQWidget *parent, const char *name)
134  : TQLineEdit(parent, name), m_EchoMode(echoMode)
135 {
136  init();
137 }
138 
139 KPasswordEdit::KPasswordEdit(EchoMode echoMode, TQWidget *parent, const char *name)
140  : TQLineEdit(parent, name)
141  , m_EchoMode( echoMode == TQLineEdit::NoEcho ? NoEcho : OneStar )
142 {
143  init();
144 }
145 
146 void KPasswordEdit::init()
147 {
148  setEchoMode(TQLineEdit::Password); // Just in case
149  setAcceptDrops(false);
150  int* t = ourMaxLength(this);
151  *t = (PassLen - 1); // the internal max length
152  m_Password = new char[PassLen];
153  m_Password[0] = '\000';
154  m_Length = 0;
155 }
156 
157 KPasswordEdit::~KPasswordEdit()
158 {
159  memset(m_Password, 0, PassLen * sizeof(char));
160  delete[] m_Password;
161  delete_d(this);
162 }
163 
164 void KPasswordEdit::insert(const TQString &txt)
165 {
166  const TQCString localTxt = txt.local8Bit();
167  const unsigned int lim = localTxt.length();
168  const int m_MaxLength = maxPasswordLength();
169  for(unsigned int i=0; i < lim; ++i)
170  {
171  const unsigned char ke = localTxt[i];
172  if (m_Length < m_MaxLength)
173  {
174  m_Password[m_Length] = ke;
175  m_Password[++m_Length] = '\000';
176  }
177  }
178  showPass();
179 }
180 
181 void KPasswordEdit::erase()
182 {
183  m_Length = 0;
184  memset(m_Password, 0, PassLen * sizeof(char));
185  setText("");
186 }
187 
188 void KPasswordEdit::focusInEvent(TQFocusEvent *e)
189 {
190  const TQString txt = text();
191  setUpdatesEnabled(false);
192  TQLineEdit::focusInEvent(e);
193  setUpdatesEnabled(true);
194  setText(txt);
195 }
196 
197 
198 void KPasswordEdit::keyPressEvent(TQKeyEvent *e)
199 {
200  switch (e->key()) {
201  case Key_Return:
202  case Key_Enter:
203  case Key_Escape:
204  e->ignore();
205  break;
206  case Key_Backspace:
207  case Key_Delete:
208  case 0x7f: // Delete
209  if (e->state() & (ControlButton | AltButton))
210  e->ignore();
211  else if (m_Length) {
212  m_Password[--m_Length] = '\000';
213  showPass();
214  }
215  break;
216  default:
217  const unsigned char ke = TQString(e->text()).local8Bit()[0];
218  if (ke >= 32) {
219  insert(e->text());
220  } else
221  e->ignore();
222  break;
223  }
224 }
225 
226 bool KPasswordEdit::event(TQEvent *e) {
227  switch(e->type()) {
228 
229  case TQEvent::MouseButtonPress:
230  case TQEvent::MouseButtonRelease:
231  case TQEvent::MouseButtonDblClick:
232  case TQEvent::MouseMove:
233  case TQEvent::IMStart:
234  case TQEvent::IMCompose:
235  return true; //Ignore
236 
237  case TQEvent::IMEnd:
238  {
239  TQIMEvent* const ie = (TQIMEvent*) e;
240  if (!ie->text().isEmpty())
241  insert( ie->text() );
242  return true;
243  }
244 
245  case TQEvent::AccelOverride:
246  {
247  TQKeyEvent* const k = (TQKeyEvent*) e;
248  switch (k->key()) {
249  case Key_U:
250  if (k->state() & ControlButton) {
251  m_Length = 0;
252  m_Password[m_Length] = '\000';
253  showPass();
254  }
255  }
256  return true; // stop bubbling
257  }
258 
259  default:
260  // Do nothing
261  break;
262  }
263  return TQLineEdit::event(e);
264 }
265 
266 void KPasswordEdit::showPass()
267 {
268  TQString tmp;
269 
270  switch (m_EchoMode) {
271  case OneStar:
272  tmp.fill('*', m_Length);
273  setText(tmp);
274  break;
275  case ThreeStars:
276  tmp.fill('*', m_Length*3);
277  setText(tmp);
278  break;
279  case NoEcho: default:
280  emit textChanged(TQString::null); //To update the password comparison if need be.
281  break;
282  }
283 }
284 
285 void KPasswordEdit::setMaxPasswordLength(int newLength)
286 {
287  if (newLength >= PassLen) newLength = PassLen - 1; // belt and braces
288  if (newLength < 0) newLength = 0;
289  int* t = ourMaxLength(this);
290  *t = newLength;
291  while (m_Length > newLength) {
292  m_Password[m_Length] = '\000';
293  --m_Length;
294  }
295  showPass();
296 }
297 
298 int KPasswordEdit::maxPasswordLength() const
299 {
300  return *(ourMaxLength(this));
301 }
302 /*
303  * Password dialog.
304  */
305 
306 KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn,
307  TQWidget *parent, const char *name)
308  : KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
309  Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
310 {
311  d->iconName = "password";
312  init();
313 }
314 
315 KPasswordDialog::KPasswordDialog(Types type, bool enableKeep, int extraBttn, const TQString& icon,
316  TQWidget *parent, const char *name )
317  : KDialogBase(parent, name, true, "", Ok|Cancel|extraBttn,
318  Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
319 {
320  if ( icon.stripWhiteSpace().isEmpty() )
321  d->iconName = "password";
322  else
323  d->iconName = icon;
324  init();
325 }
326 
327 KPasswordDialog::KPasswordDialog(int type, TQString prompt, bool enableKeep,
328  int extraBttn)
329  : KDialogBase(0L, "Password Dialog", true, "", Ok|Cancel|extraBttn,
330  Ok, true), m_Keep(enableKeep? 1 : 0), m_keepWarnLbl(0), m_Type(type), d(new KPasswordDialogPrivate)
331 {
332  d->iconName = "password";
333  init();
334  setPrompt(prompt);
335 }
336 
337 void KPasswordDialog::init()
338 {
339  m_Row = 0;
340 
341  KConfig* const cfg = KGlobal::config();
342  const KConfigGroupSaver saver(cfg, "Passwords");
343  bool def = ( qstrcmp( tqAppName(), "kdesu" ) == 0 ? defKeep : false );
344  if (m_Keep && cfg->readBoolEntry("Keep", def))
345  ++m_Keep;
346 
347  m_pMain = new TQWidget(this);
348  setMainWidget(m_pMain);
349  m_pGrid = new TQGridLayout(m_pMain, 10, 3, 0, 0);
350  m_pGrid->addColSpacing(1, 10);
351 
352  // Row 1: pixmap + prompt
353  TQLabel *lbl;
354  const TQPixmap pix( KGlobal::iconLoader()->loadIcon( d->iconName, KIcon::NoGroup, KIcon::SizeHuge, 0, 0, true));
355  if (!pix.isNull()) {
356  lbl = new TQLabel(m_pMain);
357  lbl->setPixmap(pix);
358  lbl->setAlignment(AlignHCenter|AlignVCenter);
359  lbl->setFixedSize(lbl->sizeHint());
360  m_pGrid->addWidget(lbl, 0, 0, (TQ_Alignment)AlignCenter);
361  }
362 
363  m_pHelpLbl = new TQLabel(m_pMain);
364  m_pHelpLbl->setAlignment(AlignLeft|AlignVCenter|WordBreak);
365  m_pGrid->addWidget(m_pHelpLbl, 0, 2, (TQ_Alignment)AlignLeft);
366  m_pGrid->addRowSpacing(1, 10);
367  m_pGrid->setRowStretch(1, 12);
368 
369  // Row 2+: space for 4 extra info lines
370  m_pGrid->addRowSpacing(6, 5);
371  m_pGrid->setRowStretch(6, 12);
372 
373  // Row 3: Password editor #1
374  lbl = new TQLabel(m_pMain);
375  lbl->setAlignment(AlignLeft|AlignVCenter);
376  lbl->setText(i18n("&Password:"));
377  lbl->setFixedSize(lbl->sizeHint());
378  m_pGrid->addWidget(lbl, 7, 0, (TQ_Alignment)AlignLeft);
379 
380  TQHBoxLayout *h_lay = new TQHBoxLayout();
381  m_pGrid->addLayout(h_lay, 7, 2);
382  m_pEdit = new KPasswordEdit(m_pMain);
383  m_pEdit2 = 0;
384  lbl->setBuddy(m_pEdit);
385  TQSize size = m_pEdit->sizeHint();
386  m_pEdit->setFixedHeight(size.height());
387  m_pEdit->setMinimumWidth(size.width());
388  h_lay->addWidget(m_pEdit);
389 
390  // Row 4: Password editor #2 or keep password checkbox
391 
392  if ((m_Type == Password) && m_Keep) {
393  m_pGrid->addRowSpacing(8, 10);
394  m_pGrid->setRowStretch(8, 12);
395  TQCheckBox* const cb = new TQCheckBox(i18n("&Keep password"), m_pMain);
396  cb->setFixedSize(cb->sizeHint());
397  m_keepWarnLbl = new TQLabel(m_pMain);
398  m_keepWarnLbl->setAlignment(AlignLeft|AlignVCenter|WordBreak);
399  if (m_Keep > 1) {
400  cb->setChecked(true);
401  m_keepWarnLbl->show();
402  }
403  else {
404  m_Keep = 0;
405  m_keepWarnLbl->hide();
406  }
407  connect(cb, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotKeep(bool)));
408  m_pGrid->addWidget(cb, 9, 2, (TQ_Alignment)(AlignLeft|AlignVCenter));
409 // m_pGrid->addWidget(m_keepWarnLbl, 13, 2, (TQ_Alignment)(AlignLeft|AlignVCenter));
410  m_pGrid->addMultiCellWidget(m_keepWarnLbl, 13, 13, 0, 3);
411  } else if (m_Type == NewPassword) {
412  m_pGrid->addRowSpacing(8, 10);
413  lbl = new TQLabel(m_pMain);
414  lbl->setAlignment(AlignLeft|AlignVCenter);
415  lbl->setText(i18n("&Verify:"));
416  lbl->setFixedSize(lbl->sizeHint());
417  m_pGrid->addWidget(lbl, 9, 0, (TQ_Alignment)AlignLeft);
418 
419  h_lay = new TQHBoxLayout();
420  m_pGrid->addLayout(h_lay, 9, 2);
421  m_pEdit2 = new KPasswordEdit(m_pMain);
422  lbl->setBuddy(m_pEdit2);
423  size = m_pEdit2->sizeHint();
424  m_pEdit2->setFixedHeight(size.height());
425  m_pEdit2->setMinimumWidth(size.width());
426  h_lay->addWidget(m_pEdit2);
427 
428  // Row 6: Password strength meter
429  m_pGrid->addRowSpacing(10, 10);
430  m_pGrid->setRowStretch(10, 12);
431 
432  TQHBox* const strengthBox = new TQHBox(m_pMain);
433  strengthBox->setSpacing(10);
434  m_pGrid->addMultiCellWidget(strengthBox, 11, 11, 0, 2);
435  TQLabel* const passStrengthLabel = new TQLabel(strengthBox);
436  passStrengthLabel->setAlignment(AlignLeft|AlignVCenter);
437  passStrengthLabel->setText(i18n("Password strength meter:"));
438  d->m_strengthBar = new KProgress(100, strengthBox, "PasswordStrengthMeter");
439  d->m_strengthBar->setPercentageVisible(false);
440 
441  const TQString strengthBarWhatsThis(i18n("The password strength meter gives an indication of the security "
442  "of the password you have entered. To improve the strength of "
443  "the password, try:\n"
444  " - using a longer password;\n"
445  " - using a mixture of upper- and lower-case letters;\n"
446  " - using numbers or symbols, such as #, as well as letters."));
447  TQWhatsThis::add(passStrengthLabel, strengthBarWhatsThis);
448  TQWhatsThis::add(d->m_strengthBar, strengthBarWhatsThis);
449 
450  // Row 6: Label saying whether the passwords match
451  m_pGrid->addRowSpacing(12, 10);
452  m_pGrid->setRowStretch(12, 12);
453 
454  d->m_MatchLabel = new TQLabel(m_pMain);
455  d->m_MatchLabel->setAlignment(AlignLeft|AlignVCenter|WordBreak);
456  m_pGrid->addMultiCellWidget(d->m_MatchLabel, 13, 13, 0, 2);
457  d->m_MatchLabel->setText(i18n("Passwords do not match"));
458 
459 
460  connect( m_pEdit, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(enableOkBtn()) );
461  connect( m_pEdit2, TQT_SIGNAL(textChanged(const TQString&)), TQT_SLOT(enableOkBtn()) );
462  enableOkBtn();
463  }
464 
465  erase();
466 }
467 
468 
469 KPasswordDialog::~KPasswordDialog()
470 {
471  delete d;
472 }
473 
474 
475 void KPasswordDialog::clearPassword()
476 {
477  m_pEdit->erase();
478 }
479 
480 /* KDE 4: Make it const TQString & */
481 void KPasswordDialog::setPrompt(TQString prompt)
482 {
483  m_pHelpLbl->setText(prompt);
484  m_pHelpLbl->setFixedSize(275, m_pHelpLbl->heightForWidth(275));
485 }
486 
487 void KPasswordDialog::setKeepWarning(TQString warn)
488 {
489  if (m_keepWarnLbl) {
490  m_keepWarnLbl->setText(warn);
491  }
492 }
493 
494 
495 TQString KPasswordDialog::prompt() const
496 
497 {
498  return m_pHelpLbl->text();
499 }
500 
501 
502 /* KDE 4: Make them const TQString & */
503 void KPasswordDialog::addLine(TQString key, TQString value)
504 {
505  if (m_Row > 3)
506  return;
507 
508  TQLabel *lbl = new TQLabel(key, m_pMain);
509  lbl->setAlignment(AlignLeft|AlignTop);
510  lbl->setFixedSize(lbl->sizeHint());
511  m_pGrid->addWidget(lbl, m_Row+2, 0, (TQ_Alignment)AlignLeft);
512 
513  lbl = new TQLabel(value, m_pMain);
514  lbl->setAlignment(AlignTop|WordBreak);
515  lbl->setFixedSize(275, lbl->heightForWidth(275));
516  m_pGrid->addWidget(lbl, m_Row+2, 2, (TQ_Alignment)AlignLeft);
517  ++m_Row;
518 }
519 
520 
521 void KPasswordDialog::erase()
522 {
523  m_pEdit->erase();
524  m_pEdit->setFocus();
525  if (m_Type == NewPassword)
526  m_pEdit2->erase();
527 }
528 
529 
530 void KPasswordDialog::slotOk()
531 {
532  if (m_Type == NewPassword) {
533  if (strcmp(m_pEdit->password(), m_pEdit2->password())) {
534  KMessageBox::sorry(this, i18n("You entered two different "
535  "passwords. Please try again."));
536  erase();
537  return;
538  }
539  if (d->m_strengthBar && d->m_strengthBar->progress() < d->passwordStrengthWarningLevel) {
540  int retVal = KMessageBox::warningContinueCancel(this,
541  i18n( "The password you have entered has a low strength. "
542  "To improve the strength of "
543  "the password, try:\n"
544  " - using a longer password;\n"
545  " - using a mixture of upper- and lower-case letters;\n"
546  " - using numbers or symbols as well as letters.\n"
547  "\n"
548  "Would you like to use this password anyway?"),
549  i18n("Low Password Strength"));
550  if (retVal == KMessageBox::Cancel) return;
551  }
552  }
553  if (!checkPassword(m_pEdit->password())) {
554  erase();
555  return;
556  }
557  accept();
558 }
559 
560 
561 void KPasswordDialog::slotCancel()
562 {
563  reject();
564 }
565 
566 
567 void KPasswordDialog::slotKeep(bool keep)
568 {
569  if (m_keepWarnLbl->text() != "") {
570  if (keep) {
571  m_keepWarnLbl->show();
572  }
573  else {
574  m_keepWarnLbl->hide();
575  }
576  TQTimer::singleShot(0, this, SLOT(slotLayout()));
577  }
578 
579  m_Keep = keep;
580 }
581 
582 void KPasswordDialog::slotLayout()
583 {
584  resize(sizeHint());
585 }
586 
587 
588 // static . antlarr: KDE 4: Make it const TQString & prompt
589 int KPasswordDialog::getPassword(TQCString &password, TQString prompt,
590  int *keep)
591 {
592  const bool enableKeep = (keep && *keep);
593  KPasswordDialog* const dlg = new KPasswordDialog(int(Password), prompt, enableKeep);
594  const int ret = dlg->exec();
595  if (ret == Accepted) {
596  password = dlg->password();
597  if (enableKeep)
598  *keep = dlg->keep();
599  }
600  delete dlg;
601  return ret;
602 }
603 
604 
605 // static . antlarr: KDE 4: Make it const TQString & prompt
606 int KPasswordDialog::getNewPassword(TQCString &password, TQString prompt)
607 {
608  KPasswordDialog* const dlg = new KPasswordDialog(NewPassword, prompt);
609  const int ret = dlg->exec();
610  if (ret == Accepted)
611  password = dlg->password();
612  delete dlg;
613  return ret;
614 }
615 
616 
617 // static
618 void KPasswordDialog::disableCoreDumps()
619 {
620  struct rlimit rlim;
621  rlim.rlim_cur = rlim.rlim_max = 0;
622  setrlimit(RLIMIT_CORE, &rlim);
623 }
624 
625 void KPasswordDialog::virtual_hook( int id, void* data )
626 { KDialogBase::virtual_hook( id, data ); }
627 
628 void KPasswordDialog::enableOkBtn()
629 {
630  if (m_Type == NewPassword) {
631  const bool match = strcmp(m_pEdit->password(), m_pEdit2->password()) == 0
632  && (d->allowEmptyPasswords || m_pEdit->password()[0]);
633 
634  const TQString pass(m_pEdit->password());
635 
636  const int minPasswordLength = minimumPasswordLength();
637 
638  if ((int) pass.length() < minPasswordLength) {
639  enableButtonOK(false);
640  } else {
641  enableButtonOK( match );
642  }
643 
644  if ( match && d->allowEmptyPasswords && m_pEdit->password()[0] == 0 ) {
645  d->m_MatchLabel->setText( i18n("Password is empty") );
646  } else {
647  if ((int) pass.length() < minPasswordLength) {
648  d->m_MatchLabel->setText(i18n("Password must be at least 1 character long", "Password must be at least %n characters long", minPasswordLength));
649  } else {
650  d->m_MatchLabel->setText( match? i18n("Passwords match")
651  :i18n("Passwords do not match") );
652  }
653  }
654 
655  // Password strength calculator
656  // Based on code in the Master Password dialog in Firefox
657  // (pref-masterpass.js)
658  // Original code triple-licensed under the MPL, GPL, and LGPL
659  // so is license-compatible with this file
660 
661  const double lengthFactor = d->reasonablePasswordLength / 8.0;
662 
663 
664  int pwlength = (int) (pass.length() / lengthFactor);
665  if (pwlength > 5) pwlength = 5;
666 
667  const TQRegExp numRxp("[0-9]", true, false);
668  int numeric = (int) (pass.contains(numRxp) / lengthFactor);
669  if (numeric > 3) numeric = 3;
670 
671  const TQRegExp symbRxp("\\W", false, false);
672  int numsymbols = (int) (pass.contains(symbRxp) / lengthFactor);
673  if (numsymbols > 3) numsymbols = 3;
674 
675  const TQRegExp upperRxp("[A-Z]", true, false);
676  int upper = (int) (pass.contains(upperRxp) / lengthFactor);
677  if (upper > 3) upper = 3;
678 
679  int pwstrength=((pwlength*10)-20) + (numeric*10) + (numsymbols*15) + (upper*10);
680 
681  if ( pwstrength < 0 ) {
682  pwstrength = 0;
683  }
684 
685  if ( pwstrength > 100 ) {
686  pwstrength = 100;
687  }
688  d->m_strengthBar->setProgress(pwstrength);
689 
690  }
691 }
692 
693 
694 void KPasswordDialog::setAllowEmptyPasswords(bool allowed) {
695  d->allowEmptyPasswords = allowed;
696  enableOkBtn();
697 }
698 
699 
700 bool KPasswordDialog::allowEmptyPasswords() const {
701  return d->allowEmptyPasswords;
702 }
703 
704 void KPasswordDialog::setMinimumPasswordLength(int minLength) {
705  d->minimumPasswordLength = minLength;
706  enableOkBtn();
707 }
708 
709 int KPasswordDialog::minimumPasswordLength() const {
710  return d->minimumPasswordLength;
711 }
712 
713 void KPasswordDialog::setMaximumPasswordLength(int maxLength) {
714 
715  if (maxLength < 0) maxLength = 0;
716  if (maxLength >= KPasswordEdit::PassLen) maxLength = KPasswordEdit::PassLen - 1;
717 
718  d->maximumPasswordLength = maxLength;
719 
720  m_pEdit->setMaxPasswordLength(maxLength);
721  if (m_pEdit2) m_pEdit2->setMaxPasswordLength(maxLength);
722 
723 }
724 
725 int KPasswordDialog::maximumPasswordLength() const {
726  return d->maximumPasswordLength;
727 }
728 
729 // reasonable password length code contributed by Steffen Mthing
730 
731 void KPasswordDialog::setReasonablePasswordLength(int reasonableLength) {
732 
733  if (reasonableLength < 1) reasonableLength = 1;
734  if (reasonableLength >= maximumPasswordLength()) reasonableLength = maximumPasswordLength();
735 
736  d->reasonablePasswordLength = reasonableLength;
737 
738 }
739 
740 int KPasswordDialog::reasonablePasswordLength() const {
741  return d->reasonablePasswordLength;
742 }
743 
744 
745 void KPasswordDialog::setPasswordStrengthWarningLevel(int warningLevel) {
746  if (warningLevel < 0) warningLevel = 0;
747  if (warningLevel > 99) warningLevel = 99;
748  d->passwordStrengthWarningLevel = warningLevel;
749 }
750 
751 int KPasswordDialog::passwordStrengthWarningLevel() const {
752  return d->passwordStrengthWarningLevel;
753 }
754 
755 #include "kpassdlg.moc"
KPasswordDialog::setAllowEmptyPasswords
void setAllowEmptyPasswords(bool allowed)
Allow empty passwords? - Default: false.
Definition: kpassdlg.cpp:694
KPasswordDialog::prompt
TQString prompt() const
Returns the password prompt.
Definition: kpassdlg.cpp:495
KPasswordDialog::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: kpassdlg.cpp:745
KPasswordDialog::NewPassword
The user is asked to enter a password and to confirm it a second time.
Definition: kpassdlg.h:186
KPasswordDialog::passwordStrengthWarningLevel
int passwordStrengthWarningLevel() const
Password strength level below which a warning is given.
Definition: kpassdlg.cpp:751
KPasswordDialog::~KPasswordDialog
virtual ~KPasswordDialog()
Destructs the password dialog.
Definition: kpassdlg.cpp:469
KDialogBase::Ok
Show Ok button.
Definition: kdialogbase.h:201
KIcon::NoGroup
NoGroup
KPasswordDialog::addLine
void addLine(TQString key, TQString value)
Adds a line of information to the dialog.
Definition: kpassdlg.cpp:503
KPasswordEdit::setMaxPasswordLength
void setMaxPasswordLength(int newLength)
Set the current maximum password length.
Definition: kpassdlg.cpp:285
KPasswordDialog::getNewPassword
static int getNewPassword(TQCString &password, TQString prompt)
Pops up the dialog, asks the user for a password and returns it.
Definition: kpassdlg.cpp:606
KPasswordEdit
A safe password input widget.
Definition: kpassdlg.h:39
KPasswordDialog::setPrompt
void setPrompt(TQString prompt)
Sets the password prompt.
Definition: kpassdlg.cpp:481
KPasswordEdit::password
const char * password() const
Returns the password.
Definition: kpassdlg.h:82
KDialogBase::enableButtonOK
void enableButtonOK(bool state)
Enable or disable (gray out) the OK button.
Definition: kdialogbase.cpp:848
KProgress
A progress indicator widget.
Definition: kprogress.h:46
KPasswordDialog::clearPassword
void clearPassword()
Clears the password input field.
Definition: kpassdlg.cpp:475
KGlobal::iconLoader
static KIconLoader * iconLoader()
KPasswordEdit::KPasswordEdit
KPasswordEdit(TQWidget *parent=0, const char *name=0)
Constructs a password input widget using the user&#39;s global "echo mode" setting.
Definition: kpassdlg.cpp:108
KPasswordDialog::reasonablePasswordLength
int reasonablePasswordLength() const
Password length that is expected to be reasonably safe.
Definition: kpassdlg.cpp:740
KPasswordDialog::disableCoreDumps
static void disableCoreDumps()
Static helper function that disables core dumps.
Definition: kpassdlg.cpp:618
KPasswordDialog::setMinimumPasswordLength
void setMinimumPasswordLength(int minLength)
Minimum acceptable password length.
Definition: kpassdlg.cpp:704
KMessageBox::sorry
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
Display an "Sorry" dialog.
Definition: kmessagebox.cpp:825
KPasswordDialog::password
const char * password() const
Returns the password entered.
Definition: kpassdlg.h:339
KDialogBase::Cancel
Show Cancel-button.
Definition: kdialogbase.h:204
klocale.h
KPasswordDialog::setReasonablePasswordLength
void setReasonablePasswordLength(int reasonableLength)
Password length that is expected to be reasonably safe.
Definition: kpassdlg.cpp:731
KDialogBase
A dialog base class with standard buttons and predefined layouts.
Definition: kdialogbase.h:191
KConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
KPasswordDialog::keep
bool keep() const
Returns true if the user wants to keep the password.
Definition: kpassdlg.h:351
KPasswordDialog::KPasswordDialog
KPasswordDialog(Types type, bool enableKeep, int extraBttn, TQWidget *parent=0, const char *name=0)
Constructs a password dialog.
Definition: kpassdlg.cpp:306
KConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
KPasswordDialog::minimumPasswordLength
int minimumPasswordLength() const
Minimum acceptable password length.
Definition: kpassdlg.cpp:709
KPasswordEdit::maxPasswordLength
int maxPasswordLength() const
Returns the current maximum password length.
Definition: kpassdlg.cpp:298
KDialogBase::setMainWidget
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
Definition: kdialogbase.cpp:1431
KPasswordEdit::erase
void erase()
Erases the current password.
Definition: kpassdlg.cpp:181
KIcon::SizeHuge
SizeHuge
KConfigGroupSaver
KPasswordDialog::Password
The user is asked to enter a password.
Definition: kpassdlg.h:179
KMessageBox::warningContinueCancel
static int warningContinueCancel(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, const KGuiItem &buttonContinue=KStdGuiItem::cont(), const TQString &dontAskAgainName=TQString::null, int options=Notify)
Display a "warning" dialog.
Definition: kmessagebox.cpp:585
KPasswordDialog::allowEmptyPasswords
bool allowEmptyPasswords() const
Allow empty passwords?
Definition: kpassdlg.cpp:700
KPasswordDialog
A password input dialog.
Definition: kpassdlg.h:166
KPasswordEdit::~KPasswordEdit
~KPasswordEdit()
Destructs the widget.
Definition: kpassdlg.cpp:157
KConfig
KPasswordDialog::getPassword
static int getPassword(TQCString &password, TQString prompt, int *keep=0L)
Pops up the dialog, asks the user for a password, and returns it.
Definition: kpassdlg.cpp:589
KPasswordDialog::setMaximumPasswordLength
void setMaximumPasswordLength(int maxLength)
Maximum acceptable password length.
Definition: kpassdlg.cpp:713
KPasswordEdit::insert
virtual void insert(const TQString &)
Reimplementation.
Definition: kpassdlg.cpp:164
KPasswordDialog::setKeepWarning
void setKeepWarning(TQString warn)
Sets the text to be dynamically displayed when the keep checkbox is checked.
Definition: kpassdlg.cpp:487
KGlobal::config
static KConfig * config()
KPasswordDialog::checkPassword
virtual bool checkPassword(const char *)
Virtual function that can be overridden to provide password checking in derived classes.
Definition: kpassdlg.h:397
KPasswordDialog::maximumPasswordLength
int maximumPasswordLength() const
Maximum acceptable password length.
Definition: kpassdlg.cpp:725
KPasswordDialog::Types
Types
This enum distinguishes the two operation modes of this dialog:
Definition: kpassdlg.h:175

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |