kdeui Library API Documentation

KPasswordDialog Class Reference

This dialog asks the user to enter a password. A password input dialog. More...

#include <kpassdlg.h>

Inheritance diagram for KPasswordDialog:

KDialogBase KDialog QDialog List of all members.

Public Types

enum  Types { Password, NewPassword }
 This enum distinguishes the two operation modes of this dialog:. More...


Public Methods

 KPasswordDialog (Types type, bool enableKeep, int extraBttn, QWidget *parent=0, const char *name=0)
 Constructs a password dialog.

 KPasswordDialog (int type, QString prompt, bool enableKeep=false, int extraBttn=0)
virtual ~KPasswordDialog ()
 Destructs the password dialog.

void setPrompt (QString prompt)
 Sets the password prompt.

QString prompt () const
 Returns the password prompt.

void addLine (QString key, QString value)
 Adds a line of information to the dialog.

const char * password () const
 Returns the password entered.

bool keep () const
 Returns true if the user wants to keep the password.


Static Public Methods

int getPassword (QCString &password, QString prompt, int *keep=0L)
 Pops up the dialog, asks the user for a password, and returns it.

int getNewPassword (QCString &password, QString prompt)
 Pops up the dialog, asks the user for a password and returns it.

void disableCoreDumps ()
 Static helper funtion that disables core dumps.


Protected Slots

void slotOk ()
 Activated when the Ok button has been clicked.

void slotCancel ()
 Activated when the Cancel button has been clicked.


Protected Methods

virtual bool checkPassword (const char *)
 Virtual function that can be overridden to provide password checking in derived classes.

virtual void virtual_hook (int id, void *data)

Detailed Description

This dialog asks the user to enter a password. A password input dialog.

The functions you're probably interested in are the static methods, getPassword() and getNewPassword().

Usage example

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

Security notes

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

  • 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 <jansen@kde.org>

Definition at line 127 of file kpassdlg.h.


Member Enumeration Documentation

enum KPasswordDialog::Types
 

This enum distinguishes the two operation modes of this dialog:.

Enumeration values:
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 136 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.
Version:
New in 3.0

Definition at line 199 of file kpassdlg.cpp.

Referenced by getNewPassword(), and getPassword().

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. May be removed in KDE 4.0

Definition at line 208 of file kpassdlg.cpp.

References setPrompt().

KPasswordDialog::~KPasswordDialog   [virtual]
 

Destructs the password dialog.

Definition at line 306 of file kpassdlg.cpp.


Member Function Documentation

void KPasswordDialog::setPrompt QString    prompt
 

Sets the password prompt.

Definition at line 311 of file kpassdlg.cpp.

References QLabel::setText().

Referenced by KPasswordDialog().

QString KPasswordDialog::prompt  
 

Returns the password prompt.

Definition at line 318 of file kpassdlg.cpp.

References QLabel::text().

void KPasswordDialog::addLine QString    key,
QString    value
 

Adds a line of information to the dialog.

Definition at line 325 of file kpassdlg.cpp.

References QGridLayout::addWidget(), KStdAccel::key(), QLabel::setAlignment(), and QLabel::setIndent().

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 191 of file kpassdlg.h.

References KPasswordEdit::password().

Referenced by getNewPassword(), and getPassword().

bool KPasswordDialog::keep   const [inline]
 

Returns true if the user wants to keep the password.

Definition at line 196 of file kpassdlg.h.

Referenced by getPassword().

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 385 of file kpassdlg.cpp.

References QDialog::exec(), keep(), KPasswordDialog(), password(), and Password.

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 402 of file kpassdlg.cpp.

References QDialog::exec(), KPasswordDialog(), NewPassword, and password().

void KPasswordDialog::disableCoreDumps   [static]
 

Static helper funtion that disables core dumps.

Definition at line 414 of file kpassdlg.cpp.

void KPasswordDialog::slotOk   [protected, virtual, slot]
 

Activated when the Ok button has been clicked.

The QDialog::accept() is activated.

Reimplemented from KDialogBase.

Definition at line 354 of file kpassdlg.cpp.

References QDialog::accept(), checkPassword(), NewPassword, KPasswordEdit::password(), and KMessageBox::sorry().

void KPasswordDialog::slotCancel   [protected, virtual, slot]
 

Activated when the Cancel button has been clicked.

The QDialog::reject() is activated in regular mode and QDialog::done( Cancel ) when in message box mode.

Reimplemented from KDialogBase.

Definition at line 372 of file kpassdlg.cpp.

References QDialog::reject().

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 241 of file kpassdlg.h.

Referenced by slotOk().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:06 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001