Changeset View
Changeset View
Standalone View
Standalone View
src/passworddialog.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 107 | if (!m_pwSettings) { | |||
---|---|---|---|---|---|
108 | m_pwSettings = pwquality_default_settings (); | 108 | m_pwSettings = pwquality_default_settings (); | ||
109 | pwquality_set_int_value (m_pwSettings, PWQ_SETTING_MAX_SEQUENCE, 4); | 109 | pwquality_set_int_value (m_pwSettings, PWQ_SETTING_MAX_SEQUENCE, 4); | ||
110 | if (pwquality_read_config (m_pwSettings, nullptr, nullptr) < 0) { | 110 | if (pwquality_read_config (m_pwSettings, nullptr, nullptr) < 0) { | ||
111 | qCWarning(USER_MANAGER_LOG) << "failed to read pwquality configuration\n"; | 111 | qCWarning(USER_MANAGER_LOG) << "failed to read pwquality configuration\n"; | ||
112 | return; | 112 | return; | ||
113 | } | 113 | } | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | int quality = pwquality_check (m_pwSettings, password.toUtf8().constData(), nullptr, m_username.constData(), nullptr); | 116 | // Doesn't need freeing currently. Only set to internal members of pwquality. | ||
117 | void *auxerror; | ||||
118 | int quality = pwquality_check(m_pwSettings, password.toUtf8().constData(), | ||||
119 | nullptr, m_username.constData(), &auxerror); | ||||
117 | 120 | | |||
118 | qCDebug(USER_MANAGER_LOG) << "Quality: " << quality; | 121 | qCDebug(USER_MANAGER_LOG) << "Quality: " << quality; | ||
119 | 122 | | |||
120 | QString strenght; | 123 | QString strenght; | ||
121 | QPalette palette; | 124 | QPalette palette; | ||
122 | if (quality < 0) { | 125 | if (quality < 0) { | ||
123 | palette = m_negative; | 126 | palette = m_negative; | ||
124 | strenght = errorString(quality); | 127 | strenght = errorString(quality, auxerror); | ||
125 | } else if (quality < 25) { | 128 | } else if (quality < 25) { | ||
126 | palette = m_neutral; | 129 | palette = m_neutral; | ||
127 | strenght = i18n("This password is weak"); | 130 | strenght = i18n("This password is weak"); | ||
128 | } else if (quality < 50) { | 131 | } else if (quality < 50) { | ||
129 | palette = m_positive; | 132 | palette = m_positive; | ||
130 | strenght = i18n("This password is good"); | 133 | strenght = i18n("This password is good"); | ||
131 | } else if (quality < 75) { | 134 | } else if (quality < 75) { | ||
132 | palette = m_positive; | 135 | palette = m_positive; | ||
133 | strenght = i18n("This password is very good"); | 136 | strenght = i18n("This password is very good"); | ||
134 | } else if (quality < 101) { | 137 | } else if (quality < 101) { | ||
135 | palette = m_positive; | 138 | palette = m_positive; | ||
136 | strenght = i18n("This password is excellent"); | 139 | strenght = i18n("This password is excellent"); | ||
137 | } | 140 | } | ||
138 | 141 | | |||
139 | strenghtLbl->setPalette(palette); | 142 | strenghtLbl->setPalette(palette); | ||
140 | strenghtLbl->setText(strenght); | 143 | strenghtLbl->setText(strenght); | ||
141 | buttons->button(QDialogButtonBox::Ok)->setEnabled(true); | 144 | buttons->button(QDialogButtonBox::Ok)->setEnabled(true); | ||
142 | } | 145 | } | ||
143 | 146 | | |||
144 | QString PasswordDialog::errorString(int error) | 147 | QString PasswordDialog::errorString(int error, void *auxerror) | ||
145 | { | 148 | { | ||
146 | switch(error) { | 149 | // Translations may be problematic on Debian-derived distros for packaging | ||
147 | case PWQ_ERROR_MIN_LENGTH: | 150 | // reasons. | ||
148 | { | 151 | // https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=931171 | ||
149 | int length; | 152 | // Ubuntu-derived should be fine since they have central language packages, | ||
150 | pwquality_get_int_value(m_pwSettings, PWQ_SETTING_MIN_LENGTH, &length); | 153 | // even though assignment to the gnome package is not ideal. | ||
151 | return i18ncp("Error returned when the password is invalid" | 154 | // https://bugs.launchpad.net/ubuntu/+source/libpwquality/+bug/1834480 | ||
152 | ,"The password should be at least %1 character" | 155 | char buf[PWQ_MAX_ERROR_MESSAGE_LEN]; // arbitrary size | ||
153 | ,"The password should be at least %1 characters", length); | 156 | const QString errorString = | ||
154 | } | 157 | QString::fromUtf8(pwquality_strerror(buf, PWQ_MAX_ERROR_MESSAGE_LEN, | ||
anthonyfieroni: Shouldn't be fromUtf8 ? You can't handle all languages by latin. | |||||
sitter: Oh, indeed! | |||||
155 | case PWQ_ERROR_MIN_UPPERS: | 158 | error, auxerror)); | ||
156 | { | 159 | if (!errorString.isEmpty()) { | ||
157 | int amount; | 160 | return errorString; | ||
158 | pwquality_get_int_value(m_pwSettings, PWQ_SETTING_UP_CREDIT, &amount); | 161 | } | ||
159 | return i18ncp("Error returned when the password is invalid" | | |||
160 | ,"The password should contain at least %1 uppercase letter" | | |||
161 | ,"The password should contain at least %1 uppercase letters", amount); | | |||
162 | } | | |||
163 | case PWQ_ERROR_MIN_LOWERS: | | |||
164 | { | | |||
165 | int amount; | | |||
166 | pwquality_get_int_value(m_pwSettings, PWQ_SETTING_LOW_CREDIT, &amount); | | |||
167 | return i18ncp("Error returned when the password is invalid" | | |||
168 | ,"The password should contain at least %1 lowercase letter" | | |||
169 | ,"The password should contain at least %1 lowercase letters", amount); | | |||
170 | } | | |||
171 | case PWQ_ERROR_USER_CHECK: | | |||
172 | return i18nc("Error returned when the password is invalid", "Your username should not be part of your password"); | | |||
173 | case PWQ_ERROR_GECOS_CHECK: | | |||
174 | return i18nc("Error returned when the password is invalid", "Your name should not be part of your password"); | | |||
175 | case PWQ_ERROR_MIN_DIGITS: | | |||
176 | { | | |||
177 | int amount; | | |||
178 | pwquality_get_int_value(m_pwSettings, PWQ_SETTING_DIG_CREDIT, &amount); | | |||
179 | return i18ncp("Error returned when the password is invalid" | | |||
180 | ,"The password should contain at least %1 number" | | |||
181 | ,"The password should contain at least %1 numbers", amount); | | |||
182 | } | | |||
183 | case PWQ_ERROR_MIN_OTHERS: | | |||
184 | { | | |||
185 | int amount; | | |||
186 | pwquality_get_int_value(m_pwSettings, PWQ_SETTING_OTH_CREDIT, &amount); | | |||
187 | return i18ncp("Error returned when the password is invalid" | | |||
188 | ,"The password should contain at least %1 special character (like punctuation)" | | |||
189 | ,"The password should contain at least %1 special characters (like punctuation)", amount); | | |||
190 | } | | |||
191 | case PWQ_ERROR_MIN_CLASSES: | | |||
192 | return i18nc("Error returned when the password is invalid", "The password should contain a mixture of letters, numbers, spaces and punctuation"); | | |||
193 | case PWQ_ERROR_MAX_CONSECUTIVE: | | |||
194 | return i18nc("Error returned when the password is invalid", "The password should not contain too many repeated characters"); | | |||
195 | case PWQ_ERROR_MAX_CLASS_REPEAT: | | |||
196 | return i18nc("Error returned when the password is invalid", "The password should be more varied in letters, numbers and punctuation"); | | |||
197 | case PWQ_ERROR_MAX_SEQUENCE: | | |||
198 | return i18nc("Error returned when the password is invalid", "The password should not contain sequences like 1234 or abcd"); | | |||
199 | case PWQ_ERROR_CRACKLIB_CHECK: | | |||
200 | return i18nc("Error returned when the password is invalid", "This password can't be used, it is too simple"); | | |||
201 | }; | | |||
202 | 162 | | |||
203 | return i18nc("Returned when a more specific error message has not been found" | 163 | return i18nc("Returned when a more specific error message has not been found" | ||
204 | , "Please choose another password"); | 164 | , "Please choose another password"); | ||
205 | } | 165 | } |
Shouldn't be fromUtf8 ? You can't handle all languages by latin.