KPasswordDialog Class Reference

`#include <kpassdlg.h>`

Inheritance diagram for KPasswordDialog:

## Public Types

enum | Types { Password, NewPassword }
Public Types inherited from KDialogBase
enum | ButtonCode { Help = 0x00000001, Default = 0x00000002, Ok = 0x00000004, Apply = 0x00000008, Try = 0x00000010, Cancel = 0x00000020, Close = 0x00000040, User1 = 0x00000080, User2 = 0x00000100, User3 = 0x00000200, No = 0x00000080, Yes = 0x00000100, Details = 0x00000400, Filler = 0x40000000, Stretch = 0x80000000, NoDefault }
enum | ActionButtonStyle { ActionStyle0 =0, ActionStyle1, ActionStyle2, ActionStyle3, ActionStyle4, ActionStyleMAX }
enum | DialogType { TreeList = KJanusWidget::TreeList, Tabbed = KJanusWidget::Tabbed, Plain = KJanusWidget::Plain, Swallow = KJanusWidget::Swallow, IconList = KJanusWidget::IconList }

## Public Member Functions

| KPasswordDialog (Types type, bool enableKeep, int extraBttn, QWidget *parent=0, const char *name=0)
| KPasswordDialog (int type, QString prompt, bool enableKeep=false, int extraBttn=0) KDE_DEPRECATED
| KPasswordDialog (Types type, bool enableKeep, int extraBttn, const QString &iconName, QWidget *parent=0, const char *name=0)
virtual | ~KPasswordDialog ()
void | setPrompt (QString prompt)
QString | prompt () const
void | addLine (QString key, QString value)
void | setAllowEmptyPasswords (bool allowed)
bool | allowEmptyPasswords () const
void | setMinimumPasswordLength (int minLength)
int | minimumPasswordLength () const
void | setMaximumPasswordLength (int maxLength)
int | maximumPasswordLength () const
void | setReasonablePasswordLength (int reasonableLength)
int | reasonablePasswordLength () const
void | setPasswordStrengthWarningLevel (int warningLevel)
int | passwordStrengthWarningLevel () const
const char * | password () const
void | clearPassword ()
bool | keep () const
Public Member Functions inherited from KDialogBase
| KDialogBase (QWidget *parent=0, const char *name=0, bool modal=true, const QString &caption=QString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
| KDialogBase (int dialogFace, const QString &caption, int buttonMask, ButtonCode defaultButton, QWidget *parent=0, const char *name=0, bool modal=true, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
| KDialogBase (KDialogBase::DialogType dialogFace, WFlags f, QWidget *parent=0, const char *name=0, bool modal=true, const QString &caption=QString::null, int buttonMask=Ok|Apply|Cancel, ButtonCode defaultButton=Ok, bool separator=false, const KGuiItem &user1=KGuiItem(), const KGuiItem &user2=KGuiItem(), const KGuiItem &user3=KGuiItem())
| KDialogBase (const QString &caption, int buttonMask=Yes|No|Cancel, ButtonCode defaultButton=Yes, ButtonCode escapeButton=Cancel, QWidget *parent=0, const char *name=0, bool modal=true, bool separator=false, const KGuiItem &yes=KStdGuiItem::yes(), const KGuiItem &no=KStdGuiItem::no(), const KGuiItem &cancel=KStdGuiItem::cancel())
| ~KDialogBase ()
void | setButtonBoxOrientation (int orientation)
void | setEscapeButton (ButtonCode id)
virtual void | adjustSize ()
virtual QSize | sizeHint () const
virtual QSize | minimumSizeHint () const
QFrame * | plainPage ()
QFrame * | addPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QFrame * | addPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QVBox * | addVBoxPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QVBox * | addVBoxPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QHBox * | addHBoxPage (const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QHBox * | addHBoxPage (const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QGrid * | addGridPage (int n, Orientation dir, const QString &itemName, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
QGrid * | addGridPage (int n, Orientation dir, const QStringList &items, const QString &header=QString::null, const QPixmap &pixmap=QPixmap())
void | setFolderIcon (const QStringList &path, const QPixmap &pixmap)
QFrame * | makeMainWidget ()
QVBox * | makeVBoxMainWidget ()
QHBox * | makeHBoxMainWidget ()
QGrid * | makeGridMainWidget (int n, Orientation dir)
void | enableButtonSeparator (bool state)
void | showButton (ButtonCode id, bool state)
void | showButtonOK (bool state)
void | showButtonApply (bool state)
void | showButtonCancel (bool state)
bool | showPage (int index)
int | activePageIndex () const
int | pageIndex (QWidget *widget) const
void | setMainWidget (QWidget *widget)
QWidget * | mainWidget ()
void | disableResize ()
void | setInitialSize (const QSize &s, bool noResize=false)
void | incInitialSize (const QSize &s, bool noResize=false)
QSize | configDialogSize (const QString &groupName) const
QSize | configDialogSize (KConfig &config, const QString &groupName) const
void | saveDialogSize (const QString &groupName, bool global=false)
void | saveDialogSize (KConfig &config, const QString &groupName, bool global=false) const
void | setButtonOK (const KGuiItem &item=KStdGuiItem::ok())
void | setButtonOKText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED
void | setButtonApply (const KGuiItem &item=KStdGuiItem::apply())
void | setButtonApplyText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED
void | setButtonCancel (const KGuiItem &item=KStdGuiItem::cancel())
void | setButtonCancelText (const QString &text=QString::null, const QString &tooltip=QString::null, const QString &quickhelp=QString::null) KDE_DEPRECATED
void | setButtonText (ButtonCode id, const QString &text)
void | setButtonTip (ButtonCode id, const QString &text)
void | setButtonWhatsThis (ButtonCode id, const QString &text)
void | setButtonGuiItem (ButtonCode id, const KGuiItem &item)
void | setTreeListAutoResize (bool state)
void | setShowIconsInTreeList (bool state)
void | setRootIsDecorated (bool state)
void | unfoldTreeList (bool persist=false)
void | addWidgetBelowList (QWidget *widget)
void | addButtonBelowList (const QString &text, QObject *recv, const char *slot)
void | addButtonBelowList (const KGuiItem &guiitem, QObject *recv, const char *slot)
void | setIconListAllVisible (bool state)
void | showTile (bool state)
void | getBorderWidths (int &ulx, int &uly, int &lrx, int &lry) const KDE_DEPRECATED
QRect | getContentsRect () const KDE_DEPRECATED
QSize | calculateSize (int w, int h) const
QString | helpLinkText () const
QPushButton * | actionButton (ButtonCode id)
Public Member Functions inherited from KDialog
| KDialog (QWidget *parent=0, const char *name=0, bool modal=false, WFlags f=0)

## Static Public Member Functions

static int | getPassword (QCString &password, QString prompt, int *keep=0L)
static int | getNewPassword (QCString &password, QString prompt)
static void | disableCoreDumps ()
Static Public Member Functions inherited from KDialogBase
static bool | haveBackgroundTile ()
static const QPixmap * | backgroundTile ()
static const QPixmap * | getBackgroundTile () KDE_DEPRECATED
static void | setBackgroundTile (const QPixmap *pix)
Static Public Member Functions inherited from KDialog
static int | marginHint ()
static int | spacingHint ()
static void | resizeLayout (QWidget *widget, int margin, int spacing)
static void | resizeLayout (QLayoutItem *lay, int margin, int spacing)
static void | centerOnScreen (QWidget *widget, int screen=-1)
static bool | avoidArea (QWidget *widget, const QRect &area, int screen=-1)

## Protected Slots

void | slotOk ()
void | slotCancel ()
void | slotKeep (bool)
Protected Slots inherited from KDialogBase
virtual void | slotHelp ()
virtual void | slotDefault ()
virtual void | slotDetails ()
virtual void | slotUser3 ()
virtual void | slotUser2 ()
virtual void | slotUser1 ()
virtual void | slotOk ()
virtual void | slotApply ()
virtual void | slotTry ()
virtual void | slotYes ()
virtual void | slotNo ()
virtual void | slotCancel ()
virtual void | slotClose ()
virtual void | applyPressed ()
void | updateGeometry ()
void | slotDelayedDestruct ()

## Protected Member Functions

virtual bool | checkPassword (const char *)
virtual void | virtual_hook (int id, void *data)
Protected Member Functions inherited from KDialogBase
virtual void | keyPressEvent (QKeyEvent *e)
virtual void | hideEvent (QHideEvent *)
virtual void | closeEvent (QCloseEvent *e)

## Additional Inherited Members

Public Slots inherited from KDialogBase
void | enableButton (ButtonCode id, bool state)
void | enableButtonOK (bool state)
void | enableButtonApply (bool state)
void | enableButtonCancel (bool state)
void | enableLinkedHelp (bool state)
void | delayedDestruct ()
void | setHelpLinkText (const QString &text)
void | setHelp (const QString &anchor, const QString &appname=QString::null)
void | helpClickedSlot (const QString &)
void | setDetails (bool showDetails)
void | setDetailsWidget (QWidget *detailsWidget)
void | updateBackground ()
void | cancel ()
Public Slots inherited from KDialog
virtual void | polish ()
virtual void | setCaption (const QString &caption)
virtual void | setPlainCaption (const QString &caption)
Signals inherited from KDialogBase
void | helpClicked ()
void | defaultClicked ()
void | user3Clicked ()
void | user2Clicked ()
void | user1Clicked ()
void | applyClicked ()
void | tryClicked ()
void | okClicked ()
void | yesClicked ()
void | noClicked ()
void | cancelClicked ()
void | closeClicked ()
void | apply ()
void | backgroundChanged ()
void | hidden ()
void | finished ()
void | aboutToShowDetails ()
void | aboutToShowPage (QWidget *page)
Signals inherited from KDialog
void | layoutHintChanged ()

## Detailed Description

A password input dialog.

This dialog asks the user to enter a password. The functions you're probably interested in are the static methods, getPassword() and getNewPassword().

Usage example

QCString password;
int result = KPasswordDialog::getPassword(password, i18n("Prompt message"));
if (result == KPasswordDialog::Accepted)
use(password);
KDE Password Dialog

Security notes:
Keeping passwords in memory can be a potential security hole. You should handle this situation with care.

- You may want to use disableCoreDump() to disable core dumps. Core dumps are dangerous because they are an image of the process memory, and thus include any passwords that were in memory.

- You should delete passwords as soon as they are not needed anymore. The functions getPassword() and getNewPassword() return the password as a QCString. I believe this is safer than a QString. A QString stores its characters internally as 16-bit wide values, so conversions are needed, both for creating the QString and by using it. The temporary memory used for these conversion is probably not erased. This could lead to stray passwords in memory, even if you think you erased all of them.

Author
  Geert Jansen janse.nosp@m.n@kd.nosp@m.e.org

Definition at line 166 of file kpassdlg.h.

## Member Enumeration Documentation

enum KPasswordDialog::Types

This enum distinguishes the two operation modes of this dialog:

Enumerator
Password | The user is asked to enter a password.
NewPassword | The user is asked to enter a password and to confirm it a second time. This is usually used when the user changes his password.

Definition at line 175 of file kpassdlg.h.

## Constructor & Destructor Documentation

KPasswordDialog::KPasswordDialog | ( | Types | type,
|  | bool | enableKeep,
|  | int | extraBttn,
|  | QWidget * | parent = `0`,
|  | const char * | name = `0`
| ) |  |

Constructs a password dialog.

Parameters

  type | if NewPassword is given here, the dialog contains two input fields, so that the user must confirm his password and possible typos are detected immediately.
  enableKeep | if true, a check box is shown in the dialog which allows the user to keep his password input for later.
  extraBttn | allows to show additional buttons, KDialogBase.
  parent | Passed to lower level constructor.
  name | Passed to lower level constructor

Since
  3.0

Definition at line 303 of file kpassdlg.cpp.

KPasswordDialog::KPasswordDialog | ( | int | type,
|  | QString | prompt,
|  | bool | enableKeep = `false`,
|  | int | extraBttn = `0`
| ) |  |

Deprecated:
  Variant of the previous constructor without the possibility to specify a parent. Will be removed in KDE 4.0

Definition at line 324 of file kpassdlg.cpp.

KPasswordDialog::KPasswordDialog | ( | Types | type,
|  | bool | enableKeep,
|  | int | extraBttn,
|  | const QString & | iconName,
|  | QWidget * | parent = `0`,
|  | const char * | name = `0`
| ) |  |

Construct a password dialog.

Essentially the same as above but allows the icon in the password dialog to be set via `iconName`.

Parameters

  type | if NewPassword is given here, the dialog contains two input fields, so that the user must confirm his password and possible typos are detected immediately
  enableKeep | if true, a check box is shown in the dialog which allows the user to keep his password input for later.
  extraBttn | allows to show additional buttons.
  iconName | the name of the icon to be shown in the dialog. If empty, a default icon is used
  parent | Passed to lower level constructor.
  name | Passed to lower level constructor

Since
  3.3

Definition at line 312 of file kpassdlg.cpp.

KPasswordDialog::~KPasswordDialog | ( |  | ) |

virtual

Destructs the password dialog.

Definition at line 457 of file kpassdlg.cpp.

## Member Function Documentation

void KPasswordDialog::addLine | ( | QString | key,
|  | QString | value
| ) |  |

Adds a line of information to the dialog.

Definition at line 484 of file kpassdlg.cpp.

bool KPasswordDialog::allowEmptyPasswords | ( |  | ) | const

Allow empty passwords?

Since
  3.4

Definition at line 666 of file kpassdlg.cpp.

virtual bool KPasswordDialog::checkPassword | ( | const char * |  | ) |

inline protected virtual

Virtual function that can be overridden to provide password checking in derived classes.

It should return `true` if the password is valid, `false` otherwise.

Definition at line 391 of file kpassdlg.h.

void KPasswordDialog::clearPassword | ( |  | ) |

Clears the password input field.

You might want to use this after the user failed to enter the correct password.

Since
  3.3

Definition at line 463 of file kpassdlg.cpp.

void KPasswordDialog::disableCoreDumps | ( |  | ) |

static

Static helper function that disables core dumps.

Definition at line 584 of file kpassdlg.cpp.

int KPasswordDialog::getNewPassword | ( | QCString & | password,
|  | QString | prompt
| ) |  |

static

Pops up the dialog, asks the user for a password and returns it.

The user has to enter the password twice to make sure it was entered correctly.

Parameters

  password | The password is returned in this reference parameter.
  prompt | A prompt for the password. This can be a few lines of information. The text is word broken to fit nicely in the dialog.

Returns
  Result code: Accepted or Rejected.

Definition at line 572 of file kpassdlg.cpp.

int KPasswordDialog::getPassword | ( | QCString & | password,
|  | QString | prompt,
|  | int * | keep = `0L`
| ) |  |

static

Pops up the dialog, asks the user for a password, and returns it.

Parameters

  password | The password is returned in this reference parameter.
  prompt | A prompt for the password. This can be a few lines of information. The text is word broken to fit nicely in the dialog.
  keep | Enable/disable a checkbox controlling password keeping. If you pass a null pointer, or a pointer to the value 0, the checkbox is not shown. If you pass a pointer to a nonzero value, the checkbox is shown and the result is stored in *keep.

Returns
  Result code: Accepted or Rejected.

Definition at line 555 of file kpassdlg.cpp.

bool KPasswordDialog::keep | ( |  | ) | const

inline

Returns true if the user wants to keep the password.

Definition at line 346 of file kpassdlg.h.

int KPasswordDialog::maximumPasswordLength | ( |  | ) | const

Maximum acceptable password length.

Since
  3.4

Definition at line 691 of file kpassdlg.cpp.

int KPasswordDialog::minimumPasswordLength | ( |  | ) | const

Minimum acceptable password length.

Since
  3.4

Definition at line 675 of file kpassdlg.cpp.

const char* KPasswordDialog::password | ( |  | ) | const

inline

Returns the password entered.

The memory is freed in the destructor, so you should make a copy.

Definition at line 334 of file kpassdlg.h.

int KPasswordDialog::passwordStrengthWarningLevel | ( |  | ) | const

Password strength level below which a warning is given.

Since
  3.4

Definition at line 717 of file kpassdlg.cpp.

QString KPasswordDialog::prompt | ( |  | ) | const

Returns the password prompt.

Definition at line 476 of file kpassdlg.cpp.

int KPasswordDialog::reasonablePasswordLength | ( |  | ) | const

Password length that is expected to be reasonably safe.

Since
  3.4

Definition at line 706 of file kpassdlg.cpp.

void KPasswordDialog::setAllowEmptyPasswords | ( | bool | allowed | ) |

Allow empty passwords? - Default: false.

Since
  3.4

Definition at line 660 of file kpassdlg.cpp.

void KPasswordDialog::setMaximumPasswordLength | ( | int | maxLength | ) |

Maximum acceptable password length.

Limited to 199. Default: No limit, i.e. -1

Parameters

  maxLength | The new maximum password length.

Since
  3.4

Definition at line 679 of file kpassdlg.cpp.

void KPasswordDialog::setMinimumPasswordLength | ( | int | minLength | ) |

Minimum acceptable password length.

Default: If empty passwords are forbidden, 1; Otherwise, 0.

Parameters

  minLength | The new minimum password length

Since
  3.4

Definition at line 670 of file kpassdlg.cpp.

void KPasswordDialog::setPasswordStrengthWarningLevel | ( | int | warningLevel | ) |

Set the password strength level below which a warning is given Value is in the range 0 to 99.

Empty passwords score 0; non-empty passwords score up to 100, depending on their length and whether they contain numbers, mixed case letters and punctuation.

Default: 1 - warn if the password has no discernable strength whatsoever

Parameters

  warningLevel | The level below which a warning should be given.

Since
  3.4

Definition at line 711 of file kpassdlg.cpp.

void KPasswordDialog::setPrompt | ( | QString | prompt | ) |

Sets the password prompt.

Definition at line 469 of file kpassdlg.cpp.

void KPasswordDialog::setReasonablePasswordLength | ( | int | reasonableLength | ) |

Password length that is expected to be reasonably safe.

Default: 8 - the standard UNIX password length

Parameters

  reasonableLength | The new reasonable password length.

Since
  3.4

Definition at line 697 of file kpassdlg.cpp.

The documentation for this class was generated from the following files:

- kpassdlg.h
- kpassdlg.cpp

KDE Home | KDE Accessibility Home | Description of Access Keys