QtPass Developer documentation
QtPass test coverage
Current view: top level - src/passwordconfiguration.h (source / functions) Coverage Total Hit
Test: QtPass Lines: 100.0 % 7 7
Test Date: 2026-12-03 23:34:20 Functions: 100.0 % 1 1

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2018 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief Value object for the password generator: chosen character set, its
       6              :  * alphabets and the length.
       7              :  */
       8              : #ifndef SRC_PASSWORDCONFIGURATION_H_
       9              : #define SRC_PASSWORDCONFIGURATION_H_
      10              : 
      11              : #include <QString>
      12              : #include <array>
      13              : 
      14              : /**
      15              :  * @struct PasswordConfiguration
      16              :  * @ingroup store
      17              :  * @brief Holds the password generator settings: which character set is
      18              :  * selected, the alphabet of every set, and the password length.
      19              :  *
      20              :  * Loaded from and saved to QSettings by QtPassSettings; PasswordDialog reads
      21              :  * it when the user presses "Generate" and ConfigDialog edits it.
      22              :  */
      23         4209 : struct PasswordConfiguration {
      24              :   /**
      25              :    * @brief Character set options for password generation; also the index
      26              :    * into @ref Characters.
      27              :    */
      28              :   enum CharacterSet {
      29              :     ALLCHARS = 0,  /**< Letters, digits and ASCII punctuation. */
      30              :     ALPHABETICAL,  /**< Upper- and lower-case ASCII letters only. */
      31              :     ALPHANUMERIC,  /**< ASCII letters and digits. */
      32              :     CUSTOM,        /**< User-defined alphabet, edited in the settings dialog. */
      33              :     CHARSETS_COUNT /**< Sentinel, not a character set: the number of sets,
      34              :                       used to size @ref Characters. Must stay last. */
      35              :   };
      36              :   /**
      37              :    * @brief Currently active character set selection.
      38              :    */
      39              :   CharacterSet selected{ALLCHARS};
      40              :   /**
      41              :    * @brief Length of the generated password, in characters.
      42              :    */
      43              :   int length{16};
      44              :   /**
      45              :    * @brief The alphabet of each character set, indexed by CharacterSet. Only
      46              :    * the CUSTOM entry is meant to be changed after construction.
      47              :    */
      48              :   std::array<QString, CHARSETS_COUNT> Characters;
      49              :   /**
      50              :    * @brief Construct a PasswordConfiguration with sensible defaults.
      51              :    */
      52         6312 :   PasswordConfiguration() {
      53              :     Characters[ALLCHARS] =
      54              :         "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890~!@#$%^&"
      55         6312 :         "*()_-+={}[]|:;<>,.?"; /*AllChars*/
      56              :     Characters[ALPHABETICAL] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu"
      57         6312 :                                "vwxyz"; /*Only Alphabetical*/
      58              :     Characters[ALPHANUMERIC] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstu"
      59         6312 :                                "vwxyz1234567890"; /*Alphabetical and Numerical*/
      60         6312 :     Characters[CUSTOM] = Characters[ALLCHARS];    // may be redefined by user
      61         6312 :   }
      62              : };
      63              : 
      64              : #endif // SRC_PASSWORDCONFIGURATION_H_
        

Generated by: LCOV version 2.0-1