libpwquality

Struct PWQuality

source
pub struct PWQuality { /* private fields */ }
Expand description

PWQuality instance that holds the underlying pwquality_settings_t.

Implementations§

source§

impl PWQuality

source

pub fn new() -> Result<Self, PWQError>

Create a new PWQuality instance.

Examples found in repository?
examples/example.rs (line 4)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn read_default_config(&self) -> Result<&Self, PWQError>

Parse the default configuration file.

Examples found in repository?
examples/example.rs (line 6)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn read_config<P: AsRef<Path>>(&self, path: P) -> Result<&Self, PWQError>

Parse the given configuration file.

source

pub fn generate(&self, bits: i32) -> Result<String, PWQError>

Generate a random password of entropy_bits entropy and check it according to the settings.

Examples found in repository?
examples/example.rs (line 20)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn check( &self, password: &str, old_password: Option<&str>, user: Option<&str>, ) -> Result<i32, PWQError>

Check the password according to the settings.

Examples found in repository?
examples/example.rs (line 23)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn get_min_diff(&self) -> i32

Get the minimum number of characters in the new password that must not be present in the old password.

source

pub fn min_diff(&self, value: i32) -> &Self

Set the minimum number of characters in the new password that must not be present in the old password.

source

pub fn get_min_length(&self) -> i32

Get the minimum acceptable size for the new password.

Examples found in repository?
examples/example.rs (line 11)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn min_length(&self, value: i32) -> &Self

Set the minimum acceptable size for the new password.

Examples found in repository?
examples/example.rs (line 7)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn get_digit_credit(&self) -> i32

Get the maximum credit for having digits in the new password.

source

pub fn digit_credit(&self, value: i32) -> &Self

Set the maximum credit for having digits in the new password.

source

pub fn get_uppercase_credit(&self) -> i32

Get the maximum credit for having uppercase characters in the new password.

source

pub fn uppercase_credit(&self, value: i32) -> &Self

Set the maximum credit for having uppercase characters in the new password.

source

pub fn get_lowercase_credit(&self) -> i32

Get the maximum credit for having lowercase characters in the new password.

source

pub fn lowercase_credit(&self, value: i32) -> &Self

Set the maximum credit for having lowercase characters in the new password.

source

pub fn get_other_credit(&self) -> i32

Get the maximum credit for having other characters in the new password.

source

pub fn other_credit(&self, value: i32) -> &Self

Set the maximum credit for having other characters in the new password.

source

pub fn get_min_class(&self) -> i32

Get the minimum number of required classes of characters for the new password.

source

pub fn min_class(&self, value: i32) -> &Self

Set the minimum number of required classes of characters for the new password.

source

pub fn get_max_repeat(&self) -> i32

Get the maximum number of allowed same consecutive characters in the new password.

Examples found in repository?
examples/example.rs (line 17)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn max_repeat(&self, value: i32) -> &Self

Set the maximum number of allowed same consecutive characters in the new password.

Examples found in repository?
examples/example.rs (line 8)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn get_max_class_repeat(&self) -> i32

Get the maximum number of allowed consecutive characters of the same class in the new password.

source

pub fn max_class_repeat(&self, value: i32) -> &Self

Set the maximum number of allowed consecutive characters of the same class in the new password.

source

pub fn get_max_sequence(&self) -> i32

Available on crate features v1_2 or vendored or vendored-cracklib only.

Get the maximum length of monotonic character sequences in the new password.

source

pub fn max_sequence(&self, value: i32) -> &Self

Available on crate features v1_2 or vendored or vendored-cracklib only.

Set the maximum length of monotonic character sequences in the new password.

source

pub fn get_gecos_check(&self) -> bool

Get whether to perform the passwd GECOS field check.

source

pub fn gecos_check(&self, value: bool) -> &Self

Set whether to perform the passwd GECOS field check.

source

pub fn get_dict_check(&self) -> bool

Available on crate features v1_3 or vendored or vendored-cracklib only.

Get whether to perform the dictionary check.

source

pub fn dict_check(&self, value: bool) -> &Self

Available on crate features v1_3 or vendored or vendored-cracklib only.

Set whether to perform the dictionary check.

source

pub fn get_user_check(&self) -> bool

Available on crate features v1_4 or vendored or vendored-cracklib only.

Get whether to perform the user name check.

source

pub fn user_check(&self, value: bool) -> &Self

Available on crate features v1_4 or vendored or vendored-cracklib only.

Set whether to perform the user name check.

source

pub fn get_enforcing(&self) -> bool

Available on crate features v1_4 or vendored or vendored-cracklib only.

Get whether the check is enforced.

source

pub fn enforcing(&self, value: bool) -> &Self

Available on crate features v1_4 or vendored or vendored-cracklib only.

Set whether the check is enforced.

source

pub fn get_retry_times(&self) -> i32

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Get maximum retries for the password change should be allowed.

source

pub fn retry_times(&self, value: i32) -> &Self

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Set maximum retries for the password change should be allowed.

source

pub fn get_enforce_for_root(&self) -> bool

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Get whether the check is enforced for root.

source

pub fn enforce_for_root(&self, value: bool) -> &Self

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Set whether the check is enforced for root.

source

pub fn get_local_users_only(&self) -> bool

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Get whether to check local users only.

source

pub fn local_users_only(&self, value: bool) -> &Self

Available on crate features v1_4_1 or vendored or vendored-cracklib only.

Set whether to check local users only.

source

pub fn get_user_substr(&self) -> i32

Available on crate features v1_4_5 or vendored or vendored-cracklib only.

Get the length of substrings of the user name to check.

source

pub fn user_substr(&self, value: i32) -> &Self

Available on crate features v1_4_3 or vendored or vendored-cracklib only.

Set the length of substrings of the user name to check.

source

pub fn bad_words<W>(&self, words: W) -> Result<&Self, PWQError>
where W: IntoIterator, W::Item: ToString,

Set the list of words more than 3 characters long that are forbidden.

Examples found in repository?
examples/example.rs (line 9)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn get_bad_words(&self) -> Result<Vec<String>, PWQError>

Get the list of words more than 3 characters long that are forbidden.

Examples found in repository?
examples/example.rs (line 14)
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
fn main() -> Result<(), PWQError> {
    let pwq = PWQuality::new()?;

    pwq.read_default_config()?
        .min_length(9)
        .max_repeat(2)
        .bad_words(["bad", "password"])?;

    let minlen = pwq.get_min_length();
    println!("minlen={}", minlen);

    let badwords = pwq.get_bad_words()?;
    println!("badwords={:?}", badwords);

    let maxrepeat = pwq.get_max_repeat();
    println!("maxrepeat={}", maxrepeat);

    let password = pwq.generate(32)?;
    println!("password={:?}", password);

    let score = pwq.check(&password, Some("password!"), None)?;
    println!("score={}", score);

    Ok(())
}
source

pub fn dict_path(&self, path: &str) -> Result<&Self, PWQError>

Set the path to the cracklib dictionaries.

source

pub fn get_dict_path(&self) -> Result<String, PWQError>

Get the path to the cracklib dictionaries.

Trait Implementations§

source§

impl Drop for PWQuality

source§

fn drop(&mut self)

Free pwquality settings data.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.