org.kde.koala

Class KPasswordDialog

public class KPasswordDialog extends KDialogBase

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
  •  String password;
     int result = KPasswordDialog.getPassword(password, i18n("Prompt message"));
     if (result == KPasswordDialog.Accepted)
         use(password);
     
    \image html kpassworddialog.png "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 String. I believe this is safer than a String. A String stores its characters internally as 16-bit wide values, so conversions are needed, both for creating the String 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

    UNKNOWN: A password input dialog.

    Field Summary
    static intNewPassword
    static intPassword
    This enum distinguishes the two operation modes of this dialog:
    Constructor Summary
    protected KPasswordDialog(Class dummy)
    KPasswordDialog(int type, boolean enableKeep, int extraBttn, QWidget parent, String name)
    Constructs a password dialog.
    KPasswordDialog(int type, boolean enableKeep, int extraBttn, QWidget parent)
    KPasswordDialog(int type, boolean enableKeep, int extraBttn)
    KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName, QWidget parent, String name)
    Construct a password dialog.
    KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName, QWidget parent)
    KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName)
    Method Summary
    voidaddLine(String key, String value)
    Adds a line of information to the dialog.
    booleanallowEmptyPasswords()
    Allow empty passwords?
    protected booleancheckPassword(String arg1)
    Virtual function that can be overridden to provide password checking in derived classes.
    StringclassName()
    voidclearPassword()
    Clears the password input field.
    static voiddisableCoreDumps()
    Static helper function that disables core dumps.
    voiddispose()
    Delete the wrapped C++ instance ahead of finalize()
    protected voidfinalize()
    Deletes the wrapped C++ instance
    static intgetNewPassword(StringBuffer password, String prompt)
    Pops up the dialog, asks the user for a password and returns it.
    static intgetPassword(StringBuffer password, String prompt, int[] keep)
    Pops up the dialog, asks the user for a password, and returns it.
    static intgetPassword(StringBuffer password, String prompt)
    booleanisDisposed()
    Has the wrapped C++ instance been deleted?
    booleankeep()
    Returns true if the user wants to keep the password.
    intmaximumPasswordLength()
    Maximum acceptable password length.
    QMetaObjectmetaObject()
    intminimumPasswordLength()
    Minimum acceptable password length.
    Stringpassword()
    Returns the password entered.
    intpasswordStrengthWarningLevel()
    Password strength level below which a warning is given
    Stringprompt()
    Returns the password prompt.
    intreasonablePasswordLength()
    Password length that is expected to be reasonably safe.
    voidsetAllowEmptyPasswords(boolean allowed)
    Allow empty passwords?
    voidsetMaximumPasswordLength(int maxLength)
    Maximum acceptable password length.
    voidsetMinimumPasswordLength(int minLength)
    Minimum acceptable password length.
    voidsetPasswordStrengthWarningLevel(int warningLevel)
    Set the password strength level below which a warning is given Value is in the range 0 to 99.
    voidsetPrompt(String prompt)
    Sets the password prompt.
    voidsetReasonablePasswordLength(int reasonableLength)
    Password length that is expected to be reasonably safe.
    protected voidslotCancel()
    protected voidslotKeep(boolean arg1)
    protected voidslotOk()

    Field Detail

    NewPassword

    public static final int NewPassword

    Password

    public static final int Password
    This enum distinguishes the two operation modes of this dialog:

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

    Constructor Detail

    KPasswordDialog

    protected KPasswordDialog(Class dummy)

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn, QWidget parent, String name)
    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

    UNKNOWN: Constructs a password dialog.

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn, QWidget parent)

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn)

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName, QWidget parent, String name)
    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

    UNKNOWN: Construct a password dialog.

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName, QWidget parent)

    KPasswordDialog

    public KPasswordDialog(int type, boolean enableKeep, int extraBttn, String iconName)

    Method Detail

    addLine

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

    UNKNOWN: Adds a line of information to the dialog.

    allowEmptyPasswords

    public boolean allowEmptyPasswords()
    Allow empty passwords?

    UNKNOWN: Allow empty passwords?

    checkPassword

    protected boolean checkPassword(String arg1)
    Virtual function that can be overridden to provide password checking in derived classes. It should return true if the password is valid, false otherwise.

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

    className

    public String className()

    clearPassword

    public void clearPassword()
    Clears the password input field. You might want to use this after the user failed to enter the correct password.

    UNKNOWN: Clears the password input field.

    disableCoreDumps

    public static void disableCoreDumps()
    Static helper function that disables core dumps.

    UNKNOWN: Static helper function that disables core dumps.

    dispose

    public void dispose()
    Delete the wrapped C++ instance ahead of finalize()

    finalize

    protected void finalize()
    Deletes the wrapped C++ instance

    getNewPassword

    public static int getNewPassword(StringBuffer password, String prompt)
    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.

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

    getPassword

    public static int getPassword(StringBuffer password, String prompt, int[] keep)
    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.

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

    getPassword

    public static int getPassword(StringBuffer password, String prompt)

    isDisposed

    public boolean isDisposed()
    Has the wrapped C++ instance been deleted?

    keep

    public boolean keep()
    Returns true if the user wants to keep the password.

    UNKNOWN: Returns true if the user wants to keep the password.

    maximumPasswordLength

    public int maximumPasswordLength()
    Maximum acceptable password length.

    UNKNOWN: Maximum acceptable password length.

    metaObject

    public QMetaObject metaObject()

    minimumPasswordLength

    public int minimumPasswordLength()
    Minimum acceptable password length.

    UNKNOWN: Minimum acceptable password length.

    password

    public String password()
    Returns the password entered. The memory is freed in the destructor, so you should make a copy.

    UNKNOWN: Returns the password entered.

    passwordStrengthWarningLevel

    public int passwordStrengthWarningLevel()
    Password strength level below which a warning is given

    UNKNOWN: Password strength level below which a warning is given

    prompt

    public String prompt()
    Returns the password prompt.

    UNKNOWN: Returns the password prompt.

    reasonablePasswordLength

    public int reasonablePasswordLength()
    Password length that is expected to be reasonably safe.

    UNKNOWN: Password length that is expected to be reasonably safe.

    setAllowEmptyPasswords

    public void setAllowEmptyPasswords(boolean allowed)
    Allow empty passwords? - Default: false

    UNKNOWN: Allow empty passwords? - Default: false

    setMaximumPasswordLength

    public void setMaximumPasswordLength(int maxLength)
    Maximum acceptable password length. Limited to 199. Default: No limit, i.e. -1

    Parameters: maxLength : The new maximum password length.

    UNKNOWN: Maximum acceptable password length.

    setMinimumPasswordLength

    public void setMinimumPasswordLength(int minLength)
    Minimum acceptable password length. Default: If empty passwords are forbidden, 1; Otherwise, 0.

    Parameters: minLength : The new minimum password length

    UNKNOWN: Minimum acceptable password length.

    setPasswordStrengthWarningLevel

    public void 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.

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

    setPrompt

    public void setPrompt(String prompt)
    Sets the password prompt.

    UNKNOWN: Sets the password prompt.

    setReasonablePasswordLength

    public void 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.

    UNKNOWN: Password length that is expected to be reasonably safe.

    slotCancel

    protected void slotCancel()

    slotKeep

    protected void slotKeep(boolean arg1)

    slotOk

    protected void slotOk()