1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
// Copyright (c) 2017, Lucas Satabin
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>
extern crate libc;

use libc::{c_char, c_void, c_int};

use std::ffi::{CStr, CString};

use std::ptr::{null, null_mut};

use std::path::Path;

static PWQ_SETTING_DIFF_OK: c_int = 1;
static PWQ_SETTING_MIN_LENGTH: c_int = 3;
static PWQ_SETTING_DIG_CREDIT: c_int = 4;
static PWQ_SETTING_UP_CREDIT: c_int = 5;
static PWQ_SETTING_LOW_CREDIT: c_int = 6;
static PWQ_SETTING_OTH_CREDIT: c_int = 7;
static PWQ_SETTING_MIN_CLASS: c_int = 8;
static PWQ_SETTING_MAX_REPEAT: c_int = 9;
static PWQ_SETTING_DICT_PATH: c_int = 10;
static PWQ_SETTING_MAX_CLASS_REPEAT: c_int = 11;
static PWQ_SETTING_GECOS_CHECK: c_int = 12;
static PWQ_SETTING_BAD_WORDS: c_int = 13;
static PWQ_SETTING_MAX_SEQUENCE: c_int = 14;
static PWQ_SETTING_DICT_CHECK: c_int = 15;
static PWQ_SETTING_USER_CHECK: c_int = 16;
static PWQ_SETTING_ENFORCING: c_int = 17;

/// An error returned by the underlying library.
/// The `UnknownError` should never be returned unless a new error
/// code is added in `pwquality`.
#[derive(Clone, Debug)]
pub enum Error {
    FatalFailure, // = -1;
    Integer, // = -2;
    CfgfileOpen, // = -3;
    CfgfileMalformed, // = -4;
    UnknownSetting, // = -5;
    NonIntSetting, // = -6;
    NonStrSetting, // = -7;
    MemAlloc, // = -8;
    TooSimilar, // = -9;
    MinDigits, // = -10;
    MinUppers, // = -11;
    MinLowers, // = -12;
    MinOthers, // = -13;
    MinLength, // = -14;
    Palindrome, // = -15;
    CaseChangesOnly, // = -16;
    Rotated, // = -17;
    MinClasses, // = -18;
    MaxConsecutive, // = -19;
    EmptyPassword, // = -20;
    SamePassword, // = -21;
    CracklibCheck, // = -22;
    Rng, // = -23;
    GenerationFailed, // = -24;
    UserCheck, // = -25;
    GecosCheck, // = -26;
    MaxClassRepeat, // = -27;
    BadWords, // = -28;
    MaxSequence, // = -29;

    UnknownError(i32),
}

impl Error {

    fn from_int(i: c_int) -> Self {
        match i {
            -1 => Error::FatalFailure,
            -2 => Error::Integer,
            -3 => Error::CfgfileOpen,
            -4 => Error::CfgfileMalformed,
            -5 => Error::UnknownSetting,
            -6 => Error::NonIntSetting,
            -7 => Error::NonStrSetting,
            -8 => Error::MemAlloc,
            -9 => Error::TooSimilar,
            -10 => Error::MinDigits,
            -11 => Error::MinUppers,
            -12 => Error::MinLowers,
            -13 => Error::MinOthers,
            -14 => Error::MinLength,
            -15 => Error::Palindrome,
            -16 => Error::CaseChangesOnly,
            -17 => Error::Rotated,
            -18 => Error::MinClasses,
            -19 => Error::MaxConsecutive,
            -20 => Error::EmptyPassword,
            -21 => Error::SamePassword,
            -22 => Error::CracklibCheck,
            -23 => Error::Rng,
            -24 => Error::GenerationFailed,
            -25 => Error::UserCheck,
            -26 => Error::GecosCheck,
            -27 => Error::MaxClassRepeat,
            -28 => Error::BadWords,
            -29 => Error::MaxSequence,
            _ => Error::UnknownError(i)
        }
    }

}

enum OpaqueSettings{}

#[link(name = "pwquality")]
extern {
    fn pwquality_default_settings() -> *const OpaqueSettings;
    fn pwquality_free_settings(pwq: *const OpaqueSettings);
    fn pwquality_read_config(pwq: *const OpaqueSettings, cfgfile: *const c_char, auxerror: *mut *mut c_void) -> c_int;
    fn pwquality_set_int_value(pwq: *const OpaqueSettings, setting: c_int, value: c_int) -> c_int;
    fn pwquality_set_str_value(pwq: *const OpaqueSettings, setting: c_int, value: *const c_char) -> c_int;
    fn pwquality_get_int_value(pwq: *const OpaqueSettings, setting: c_int, value: *mut c_int) -> c_int;
    fn pwquality_get_str_value(pwq: *const OpaqueSettings, setting: c_int, value: *mut *mut c_char) -> c_int;

    fn pwquality_generate(pwq: *const OpaqueSettings, entropy_bits: c_int, password: *mut *mut c_char) -> c_int;
    fn pwquality_check(pwq: *const OpaqueSettings, password: *const c_char, oldpassword: *const c_char, user: *const c_char, auxerror: *mut *mut c_void) -> c_int;

}

/// Representation of an instance of `pwquality`.
/// Each instance has its own settings, that can be
/// changed.
#[derive(Debug)]
pub struct PWQuality {
    pwq: *const OpaqueSettings
}

impl PWQuality {

    /// Creates a new isntance with default settings.
    pub fn new() -> Self {
        let pwq = unsafe {
            pwquality_default_settings()
        };
        PWQuality {
            pwq
        }
    }

    /// Creates a new instance with default configuration.
    #[inline]
    pub fn from_default_config() -> Result<Self, Error> {
        PWQuality::from_optional_config(None::<&str>)
    }

    /// Creates a new instance with given configuration file.
    #[inline]
    pub fn from_config<P: AsRef<Path>>(config_path: P) -> Result<Self, Error> {
        PWQuality::from_optional_config(Some(config_path))
    }

    /// Creates a new instance with given configuration file.
    /// If `None` is passed, then default configuration is used.
    pub fn from_optional_config<P: AsRef<Path>>(config_path: Option<P>) -> Result<Self, Error> {
        let c_path = match config_path {
            Some(config_path) => CString::new(config_path.as_ref().to_str().unwrap()).unwrap().as_ptr(),
            None => null()
        };

        let (res, pwq) = unsafe {
            let pwq = pwquality_default_settings();
            let res = pwquality_read_config(pwq, c_path, null_mut());
            (res, pwq)
        };
        if res < 0 {
            Err(Error::from_int(res))
        } else {
            Ok(PWQuality {
                pwq
            })
        }
    }

    /// Sets the minimum number of changes required between old and new password.
    /// A value of `None` disables the check.
    pub fn set_min_diff(&self, min: Option<i32>) {
        let val = min.unwrap_or_else(|| { 0 });
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_DIFF_OK, val);
            assert!(res == 0);
        }
    }

    /// Returns the minimum number of changes required between old and new password.
    /// Returns `None` if check is disabled.
    pub fn get_min_diff(&self) -> Option<i32> {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_DIFF_OK, result);
            assert!(res == 0);
            if *result == 0 {
                None
            } else {
                Some(*result)
            }
        }
    }

    /// Sets the minimum accepted length for a password.
    /// Any number less than `6` will be replaced by `6`.
    pub fn set_min_length(&self, min: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_MIN_LENGTH, min);
            assert!(res == 0);
        }
    }

    /// Returns the minimum accepted length for a password.
    pub fn get_min_length(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_MIN_LENGTH, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the digit credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having digits in a password;
    ///  - if `credit < 0`, it represents the minimum number of digits required in a password.
    pub fn set_digit_credit(&self, credit: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_DIG_CREDIT, credit);
            assert!(res == 0);
        }
    }

    /// Returns the digit credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having digits in a password;
    ///  - if `credit < 0`, it represents the minimum number of digits required in a password.
    pub fn get_digit_credit(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_DIG_CREDIT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the uppercase letter credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having uppercase letters in a password;
    ///  - if `credit < 0`, it represents the minimum number of uppercase letters required in a password.
    pub fn set_uppercase_credit(&self, credit: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_UP_CREDIT, credit);
            assert!(res == 0);
        }
    }

    /// Returns the uppercase letter credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having uppercase letters in a password;
    ///  - if `credit < 0`, it represents the minimum number of uppercase letters required in a password.
    pub fn get_uppercase_credit(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_UP_CREDIT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the lowercase letter credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having lowercase letters in a password;
    ///  - if `credit < 0`, it represents the minimum number of lowercase letters required in a password.
    pub fn set_lowercase_credit(&self, credit: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_LOW_CREDIT, credit);
            assert!(res == 0);
        }
    }

    /// Returns the lowercase letter credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having lowercase letters in a password;
    ///  - if `credit < 0`, it represents the minimum number of lowercase letters required in a password.
    pub fn get_lowercase_credit(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_LOW_CREDIT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the other character credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having other characters in a password;
    ///  - if `credit < 0`, it represents the minimum number of other characters required in a password.
    pub fn set_other_credit(&self, credit: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_OTH_CREDIT, credit);
            assert!(res == 0);
        }
    }

    /// Returns the other character credit:
    ///
    ///  - if `credit >= 0`, it represents the maximum credit for having other characters in a password;
    ///  - if `credit < 0`, it represents the minimum number of other characters required in a password.
    pub fn get_other_credit(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_OTH_CREDIT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the minimum required number of classes in a password.
    /// There a four available classes:
    ///
    ///  - digits: `[0-9]`
    ///  - lowercase letters: `[a-z]`
    ///  - uppercase letters: `[A-Z]`
    ///  - other characters: `!$%&#…`
    pub fn set_min_classes(&self, min: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_MIN_CLASS, min);
            assert!(res == 0);
        }
    }

    /// Returns the minimum required number of classes in a password.
    pub fn get_min_classes(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_MIN_CLASS, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the maximum size of allowed repeated characters sequences in a password.
    /// A value of `0` disables this check.
    pub fn set_max_repeat(&self, max: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_MAX_REPEAT, max);
            assert!(res == 0);
        }
    }

    /// Returns the maximum size of allowed repeated characters sequences in a password.
    pub fn get_max_repeat(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_MAX_REPEAT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the maximum size of allowed characters sequences of a same class in a
    /// password.
    /// A value of `0` disables this check,
    pub fn set_max_class_repeat(&self, max: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_MAX_CLASS_REPEAT, max);
            assert!(res == 0);
        }
    }

    /// Returns the maximum size of allowed characters sequences of a same class in a
    /// password.
    pub fn get_max_class_repeat(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_MAX_CLASS_REPEAT, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets the maximum size allowed for monotonic character sequences such as `12345` or `fedcb`
    /// in a password.
    /// A value of `0` disables this check.
    pub fn set_max_sequence(&self, max: i32) {
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_MAX_SEQUENCE, max);
            assert!(res == 0);
        }
    }

    /// Returns the maximum size allowed for monotonic character sequences such as `12345` or `fedcb`
    /// in a password.
    pub fn get_max_sequence(&self) -> i32 {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_MAX_SEQUENCE, result);
            assert!(res == 0);
            *result
        }
    }

    /// Sets whether the check for the presence of words longer than 3 characters present in the
    /// `passwd` GECOS field of a user in a password is enabled.
    pub fn set_gecos_check(&self, check: bool) {
        let value = if check { 1 } else { 0 };
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_GECOS_CHECK, value);
            assert!(res == 0);
        }
    }

    /// Returns whether the check for the presence of words longer than 3 characters present in the
    /// `passwd` GECOS field of a user in a password is enabled.
    pub fn get_gecos_check(&self) -> bool {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_GECOS_CHECK, result);
            assert!(res == 0);
            *result != 0
        }
    }

    /// Sets whether the check that a password is contained in a dictionary is enabled.
    pub fn set_dictionary_check(&self, check: bool) {
        let value = if check { 1 } else { 0 };
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_DICT_CHECK, value);
            assert!(res == 0);
        }
    }

    /// Returns whether the check that a password is contained in a dictionary is enabled.
    pub fn get_dictionary_check(&self) -> bool {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_DICT_CHECK, result);
            assert!(res == 0);
            *result != 0
        }
    }

    /// Sets whether the check of username presence in a password is enabled.
    pub fn set_user_check(&self, check: bool) {
        let value = if check { 1 } else { 0 };
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_USER_CHECK, value);
            assert!(res == 0);
        }
    }

    /// Returns whether the check of username presence in a password is enabled.
    pub fn get_user_check(&self) -> bool {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_USER_CHECK, result);
            assert!(res == 0);
            *result != 0
        }
    }

    /// Sets whether a password that does not pass the checks should be rejected.
    pub fn set_enforcing(&self, check: bool) {
        let value = if check { 1 } else { 0 };
        unsafe {
            let res = pwquality_set_int_value(self.pwq, PWQ_SETTING_ENFORCING, value);
            assert!(res == 0);
        }
    }

    /// Returns whether a password that does not pass the checks should be rejected.
    pub fn get_enforcing(&self) -> bool {
        unsafe {
            let result: *mut i32 = &mut 0;
            let res = pwquality_get_int_value(self.pwq, PWQ_SETTING_ENFORCING, result);
            assert!(res == 0);
            *result != 0
        }
    }

    /// Sets the path to the dictionary to use (other than the default cracklib one).
    pub fn set_dictionary_path(&self, path: String) -> Result<(), Error>{
        let c_path = CString::new(path.as_str()).unwrap();
        unsafe {
            let res = pwquality_set_str_value(self.pwq, PWQ_SETTING_DICT_PATH, c_path.as_ptr());
            if res == 0 {
                Ok(())
            } else {
                Err(Error::from_int(res))
            }
        }
    }

    /// Returns the path to the dictionary to use (if any other than the default cracklib one).
    pub fn get_dictionary_path(&self) -> Result<Option<String>, Error> {
        let (res, ptr) =
            unsafe {
                let mut result = 0 as *mut c_char;
                let res = pwquality_get_str_value(self.pwq, PWQ_SETTING_DICT_PATH, (&mut result) as *mut _ as *mut *mut c_char);
                (res, result)
            };
        if res < 0 {
            Err(Error::from_int(res))
        } else if ptr == (0 as *mut c_char) {
            Ok(None)
        } else {
            let str = unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() };
            Ok(Some(str))
        }
    }

    /// Sets the list of words longer than 3 characters that are not allowed in a password.
    /// Words cannot contain whitespaces, otherwise will be considered as separate words.
    pub fn set_bad_words(&self, bad_words: Vec<String>) -> Result<(), Error> {
        let joined_str = bad_words.join(" ");
        let c_str = CString::new(joined_str.as_str()).unwrap();
        unsafe {
            let res = pwquality_set_str_value(self.pwq, PWQ_SETTING_BAD_WORDS, c_str.as_ptr());
            if res == 0 {
                Ok(())
            } else {
                Err(Error::from_int(res))
            }
        }
    }

    /// Returns the list of forbidden words in a password.
    pub fn get_bad_words(&self) -> Result<Vec<String>, Error> {
        let (res, ptr) =
            unsafe {
                let mut result = 0 as *mut c_char;
                let res = pwquality_get_str_value(self.pwq, PWQ_SETTING_BAD_WORDS, (&mut result) as *mut _ as *mut *mut c_char);
                (res, result)
            };
        if res < 0 {
            Err(Error::from_int(res))
        } else if ptr == (0 as *mut c_char) {
            Ok(vec![])
        } else {
            let str = unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() };
            let result = str.split_whitespace().map(String::from).collect();
            Ok(result)
        }
    }

    /// Generates a password with the given number of bits of entropy.
    pub fn generate_password(&self, entropy: i32) -> Result<String, Error> {
        let (res, ptr) =
            unsafe {
                let mut result = 0 as *mut c_char;
                let res = pwquality_generate(self.pwq, entropy, (&mut result) as *mut _ as *mut *mut c_char);
                (res, result)
            };
        if res < 0 {
            Err(Error::from_int(res))
        } else if ptr == (0 as *mut c_char) {
            Ok("".to_owned())
        } else {
            let pwd = unsafe { CStr::from_ptr(ptr).to_string_lossy().into_owned() };
            Ok(pwd)
        }
    }

    /// Checks a password according to the settings and returns the computed score.
    pub fn check(&self, password: String, old_password: Option<String>, username: Option<String>) -> Result<i32, Error> {
        unsafe {
            let c_password = CString::new(password).unwrap();
            let res =
                match (old_password, username) {
                    (Some(old_password), Some(username)) => {
                        let c_old_password = CString::new(old_password).unwrap();
                        let c_user = CString::new(username).unwrap();
                        pwquality_check(self.pwq, c_password.as_ptr(), c_old_password.as_ptr(), c_user.as_ptr(), null_mut())
                    },
                    (Some(old_password), None) => {
                        let c_old_password = CString::new(old_password).unwrap();
                        pwquality_check(self.pwq, c_password.as_ptr(), c_old_password.as_ptr(), null(), null_mut())
                    },
                    (None, Some(username)) => {
                        let c_user = CString::new(username).unwrap();
                        pwquality_check(self.pwq, c_password.as_ptr(), null(), c_user.as_ptr(), null_mut())
                    },
                    (None, None) =>
                        pwquality_check(self.pwq, c_password.as_ptr(), null(), null(), null_mut())
                };
            if res < 0 {
                Err(Error::from_int(res))
            } else {
                Ok(res)
            }
        }
    }

}

impl Drop for PWQuality {
    fn drop(&mut self) {
        unsafe {
            // free the memory allocated in the C library
            pwquality_free_settings(self.pwq);
        }
    }
}