Kirigami-addons

zxcvbn.h
1// C implementation of the zxcvbn password strength estimation method.
2// SPDX-FileCopyrightText: 2015-2017 Tony Evans
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7/* If this is defined, the dictiononary data is read from file. When undefined */
8/* dictionary data is included in the source code. */
9/*#define USE_DICT_FILE */
10
11/* If this is defined, C++ builds which read dictionary data from file will use */
12/* stdio FILE streams (and fopen,fread,fclose). When undefined, C++ builds will */
13/* use std::ifstream to read dictionary data. Ignored for C builds (stdio FILE */
14/* streams are always used). */
15/*#define USE_FILE_IO */
16
17#ifndef __cplusplus
18/* C build. Use the standard malloc/free for heap memory */
19#include <stdlib.h>
20#define MallocFn(T, N) ((T *)malloc((N) * sizeof(T)))
21#define FreeFn(P) free(P)
22
23#else
24
25/* C++ build. Use the new/delete operators for heap memory */
26#define MallocFn(T, N) (new T[N])
27#define FreeFn(P) (delete[] P)
28
29#endif
30
31/* Enum for the types of match returned in the Info arg to ZxcvbnMatch */
32typedef enum {
33 NON_MATCH, /* 0 */
34 BRUTE_MATCH, /* 1 */
35 DICTIONARY_MATCH, /* 2 */
36 DICT_LEET_MATCH, /* 3 */
37 USER_MATCH, /* 4 */
38 USER_LEET_MATCH, /* 5 */
39 REPEATS_MATCH, /* 6 */
40 SEQUENCE_MATCH, /* 7 */
41 SPATIAL_MATCH, /* 8 */
42 DATE_MATCH, /* 9 */
43 YEAR_MATCH, /* 10 */
44 MULTIPLE_MATCH = 32 /* Added to above to indicate matching part has been repeated */
45} ZxcTypeMatch_t;
46
47/* Linked list of information returned in the Info arg to ZxcvbnMatch */
48struct ZxcMatch {
49 int Begin; /* Char position of beginning of match */
50 int Length; /* Number of chars in the match */
51 double Entrpy; /* The entropy of the match */
52 double MltEnpy; /* Entropy with additional allowance for multipart password */
53 ZxcTypeMatch_t Type; /* Type of match (Spatial/Dictionary/Order/Repeat) */
54 struct ZxcMatch *Next;
55};
56typedef struct ZxcMatch ZxcMatch_t;
57
58#ifdef __cplusplus
59extern "C" {
60#endif
61
62#ifdef USE_DICT_FILE
63
64/**********************************************************************************
65 * Read the dictionary data from the given file. Returns 1 if OK, 0 if error.
66 * Called once at program startup.
67 */
68int ZxcvbnInit(const char *);
69
70/**********************************************************************************
71 * Free the dictionary data after use. Called once at program shutdown.
72 */
73void ZxcvbnUnInit();
74
75#else
76
77/* As the dictionary data is included in the source, define these functions to do nothing. */
78#define ZxcvbnInit(s) 1
79#define ZxcvbnUnInit() \
80 do { \
81 } while (0)
82
83#endif
84
85/**********************************************************************************
86 * The main password matching function. May be called multiple times.
87 * The parameters are:
88 * Passwd The password to be tested. Null terminated string.
89 * UserDict User supplied dictionary words to be considered particularly bad. Passed
90 * as a pointer to array of string pointers, with null last entry (like
91 * the argv parameter to main()). May be null or point to empty array when
92 * there are no user dictionary words.
93 * Info The address of a pointer variable to receive information on the parts
94 * of the password. This parameter can be null if no information is wanted.
95 * The data should be freed by calling ZxcvbnFreeInfo().
96 *
97 * Returns the entropy of the password (in bits).
98 */
99double ZxcvbnMatch(const char *Passwd, const char *UserDict[], ZxcMatch_t **Info);
100
101/**********************************************************************************
102 * Free the data returned in the Info parameter to ZxcvbnMatch().
103 */
104void ZxcvbnFreeInfo(ZxcMatch_t *Info);
105
106#ifdef __cplusplus
107}
108#endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:53:19 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.