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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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?
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(())
}
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.