pub struct PWQuality { /* private fields */ }Expand description
PWQuality instance that holds the underlying pwquality_settings_t.
Implementations§
Source§impl PWQuality
impl PWQuality
Sourcepub fn new() -> Result<Self, PWQError>
pub fn new() -> Result<Self, PWQError>
Create a new PWQuality instance.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn read_default_config(&self) -> Result<&Self, PWQError>
pub fn read_default_config(&self) -> Result<&Self, PWQError>
Parse the default configuration file.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn read_config<P: AsRef<Path>>(&self, path: P) -> Result<&Self, PWQError>
pub fn read_config<P: AsRef<Path>>(&self, path: P) -> Result<&Self, PWQError>
Parse the given configuration file.
Sourcepub fn generate(&self, bits: i32) -> Result<String, PWQError>
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?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn check(
&self,
password: &str,
old_password: Option<&str>,
user: Option<&str>,
) -> Result<i32, PWQError>
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?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn get_min_diff(&self) -> i32
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.
Sourcepub fn min_diff(&self, value: i32) -> &Self
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.
Sourcepub fn get_min_length(&self) -> i32
pub fn get_min_length(&self) -> i32
Get the minimum acceptable size for the new password.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn min_length(&self, value: i32) -> &Self
pub fn min_length(&self, value: i32) -> &Self
Set the minimum acceptable size for the new password.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn get_digit_credit(&self) -> i32
pub fn get_digit_credit(&self) -> i32
Get the maximum credit for having digits in the new password.
Sourcepub fn digit_credit(&self, value: i32) -> &Self
pub fn digit_credit(&self, value: i32) -> &Self
Set the maximum credit for having digits in the new password.
Sourcepub fn get_uppercase_credit(&self) -> i32
pub fn get_uppercase_credit(&self) -> i32
Get the maximum credit for having uppercase characters in the new password.
Sourcepub fn uppercase_credit(&self, value: i32) -> &Self
pub fn uppercase_credit(&self, value: i32) -> &Self
Set the maximum credit for having uppercase characters in the new password.
Sourcepub fn get_lowercase_credit(&self) -> i32
pub fn get_lowercase_credit(&self) -> i32
Get the maximum credit for having lowercase characters in the new password.
Sourcepub fn lowercase_credit(&self, value: i32) -> &Self
pub fn lowercase_credit(&self, value: i32) -> &Self
Set the maximum credit for having lowercase characters in the new password.
Sourcepub fn get_other_credit(&self) -> i32
pub fn get_other_credit(&self) -> i32
Get the maximum credit for having other characters in the new password.
Sourcepub fn other_credit(&self, value: i32) -> &Self
pub fn other_credit(&self, value: i32) -> &Self
Set the maximum credit for having other characters in the new password.
Sourcepub fn get_min_class(&self) -> i32
pub fn get_min_class(&self) -> i32
Get the minimum number of required classes of characters for the new password.
Sourcepub fn min_class(&self, value: i32) -> &Self
pub fn min_class(&self, value: i32) -> &Self
Set the minimum number of required classes of characters for the new password.
Sourcepub fn get_max_repeat(&self) -> i32
pub fn get_max_repeat(&self) -> i32
Get the maximum number of allowed same consecutive characters in the new password.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn max_repeat(&self, value: i32) -> &Self
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?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn get_max_class_repeat(&self) -> i32
pub fn get_max_class_repeat(&self) -> i32
Get the maximum number of allowed consecutive characters of the same class in the new password.
Sourcepub fn max_class_repeat(&self, value: i32) -> &Self
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.
Sourcepub fn get_max_sequence(&self) -> i32
Available on crate features v1_2 or vendored or vendored-cracklib only.
pub fn get_max_sequence(&self) -> i32
v1_2 or vendored or vendored-cracklib only.Get the maximum length of monotonic character sequences in the new password.
Sourcepub fn max_sequence(&self, value: i32) -> &Self
Available on crate features v1_2 or vendored or vendored-cracklib only.
pub fn max_sequence(&self, value: i32) -> &Self
v1_2 or vendored or vendored-cracklib only.Set the maximum length of monotonic character sequences in the new password.
Sourcepub fn get_gecos_check(&self) -> bool
pub fn get_gecos_check(&self) -> bool
Get whether to perform the passwd GECOS field check.
Sourcepub fn gecos_check(&self, value: bool) -> &Self
pub fn gecos_check(&self, value: bool) -> &Self
Set whether to perform the passwd GECOS field check.
Sourcepub fn get_dict_check(&self) -> bool
Available on crate features v1_3 or vendored or vendored-cracklib only.
pub fn get_dict_check(&self) -> bool
v1_3 or vendored or vendored-cracklib only.Get whether to perform the dictionary check.
Sourcepub fn dict_check(&self, value: bool) -> &Self
Available on crate features v1_3 or vendored or vendored-cracklib only.
pub fn dict_check(&self, value: bool) -> &Self
v1_3 or vendored or vendored-cracklib only.Set whether to perform the dictionary check.
Sourcepub fn get_user_check(&self) -> bool
Available on crate features v1_4 or vendored or vendored-cracklib only.
pub fn get_user_check(&self) -> bool
v1_4 or vendored or vendored-cracklib only.Get whether to perform the user name check.
Sourcepub fn user_check(&self, value: bool) -> &Self
Available on crate features v1_4 or vendored or vendored-cracklib only.
pub fn user_check(&self, value: bool) -> &Self
v1_4 or vendored or vendored-cracklib only.Set whether to perform the user name check.
Sourcepub fn get_enforcing(&self) -> bool
Available on crate features v1_4 or vendored or vendored-cracklib only.
pub fn get_enforcing(&self) -> bool
v1_4 or vendored or vendored-cracklib only.Get whether the check is enforced.
Sourcepub fn enforcing(&self, value: bool) -> &Self
Available on crate features v1_4 or vendored or vendored-cracklib only.
pub fn enforcing(&self, value: bool) -> &Self
v1_4 or vendored or vendored-cracklib only.Set whether the check is enforced.
Sourcepub fn get_retry_times(&self) -> i32
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn get_retry_times(&self) -> i32
v1_4_1 or vendored or vendored-cracklib only.Get maximum retries for the password change should be allowed.
Sourcepub fn retry_times(&self, value: i32) -> &Self
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn retry_times(&self, value: i32) -> &Self
v1_4_1 or vendored or vendored-cracklib only.Set maximum retries for the password change should be allowed.
Sourcepub fn get_enforce_for_root(&self) -> bool
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn get_enforce_for_root(&self) -> bool
v1_4_1 or vendored or vendored-cracklib only.Get whether the check is enforced for root.
Sourcepub fn enforce_for_root(&self, value: bool) -> &Self
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn enforce_for_root(&self, value: bool) -> &Self
v1_4_1 or vendored or vendored-cracklib only.Set whether the check is enforced for root.
Sourcepub fn get_local_users_only(&self) -> bool
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn get_local_users_only(&self) -> bool
v1_4_1 or vendored or vendored-cracklib only.Get whether to check local users only.
Sourcepub fn local_users_only(&self, value: bool) -> &Self
Available on crate features v1_4_1 or vendored or vendored-cracklib only.
pub fn local_users_only(&self, value: bool) -> &Self
v1_4_1 or vendored or vendored-cracklib only.Set whether to check local users only.
Sourcepub fn get_user_substr(&self) -> i32
Available on crate features v1_4_5 or vendored or vendored-cracklib only.
pub fn get_user_substr(&self) -> i32
v1_4_5 or vendored or vendored-cracklib only.Get the length of substrings of the user name to check.
Sourcepub fn user_substr(&self, value: i32) -> &Self
Available on crate features v1_4_3 or vendored or vendored-cracklib only.
pub fn user_substr(&self, value: i32) -> &Self
v1_4_3 or vendored or vendored-cracklib only.Set the length of substrings of the user name to check.
Sourcepub fn bad_words<W>(&self, words: W) -> Result<&Self, PWQError>
pub fn bad_words<W>(&self, words: W) -> Result<&Self, PWQError>
Set the list of words more than 3 characters long that are forbidden.
Examples found in repository?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn get_bad_words(&self) -> Result<Vec<String>, PWQError>
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?
3fn main() -> Result<(), PWQError> {
4 let pwq = PWQuality::new()?;
5
6 pwq.read_default_config()?
7 .min_length(9)
8 .max_repeat(2)
9 .bad_words(["bad", "password"])?;
10
11 let minlen = pwq.get_min_length();
12 println!("minlen={}", minlen);
13
14 let badwords = pwq.get_bad_words()?;
15 println!("badwords={:?}", badwords);
16
17 let maxrepeat = pwq.get_max_repeat();
18 println!("maxrepeat={}", maxrepeat);
19
20 let password = pwq.generate(32)?;
21 println!("password={:?}", password);
22
23 let score = pwq.check(&password, Some("password!"), None)?;
24 println!("score={}", score);
25
26 Ok(())
27}Sourcepub fn dict_path(&self, path: &str) -> Result<&Self, PWQError>
pub fn dict_path(&self, path: &str) -> Result<&Self, PWQError>
Set the path to the cracklib dictionaries.
Sourcepub fn get_dict_path(&self) -> Result<String, PWQError>
pub fn get_dict_path(&self) -> Result<String, PWQError>
Get the path to the cracklib dictionaries.