-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sensitive to password strength and password policy
- Loading branch information
1 parent
faa3444
commit 817cbe3
Showing
5 changed files
with
53 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
use bitwarden_crypto::SensitiveString; | ||
use zxcvbn::zxcvbn; | ||
|
||
const GLOBAL_INPUTS: [&str; 3] = ["bitwarden", "bit", "warden"]; | ||
|
||
pub(crate) fn password_strength( | ||
password: String, | ||
password: SensitiveString, | ||
email: String, | ||
additional_inputs: Vec<String>, | ||
) -> u8 { | ||
|
@@ -13,7 +14,7 @@ pub(crate) fn password_strength( | |
let mut arr: Vec<_> = inputs.iter().map(String::as_str).collect(); | ||
arr.extend(GLOBAL_INPUTS); | ||
|
||
zxcvbn(&password, &arr).map_or(0, |e| e.score()) | ||
zxcvbn(password.expose(), &arr).map_or(0, |e| e.score()) | ||
} | ||
|
||
fn email_to_user_inputs(email: &str) -> Vec<String> { | ||
|
@@ -31,6 +32,8 @@ fn email_to_user_inputs(email: &str) -> Vec<String> { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use bitwarden_crypto::SensitiveString; | ||
|
||
use super::{email_to_user_inputs, password_strength}; | ||
|
||
#[test] | ||
|
@@ -44,7 +47,8 @@ mod tests { | |
]; | ||
|
||
for (password, email, expected) in cases { | ||
let result = password_strength(password.to_owned(), email.to_owned(), vec![]); | ||
let result = | ||
password_strength(SensitiveString::test(password), email.to_owned(), vec![]); | ||
assert_eq!(expected, result, "{email}: {password}"); | ||
} | ||
} | ||
|
@@ -54,14 +58,14 @@ mod tests { | |
let password = "asdfjkhkjwer!"; | ||
|
||
let result = password_strength( | ||
password.to_owned(), | ||
SensitiveString::test(password), | ||
"[email protected]".to_owned(), | ||
vec![], | ||
); | ||
assert_eq!(result, 4); | ||
|
||
let result = password_strength( | ||
password.to_owned(), | ||
SensitiveString::test(password), | ||
"[email protected]".to_owned(), | ||
vec![], | ||
); | ||
|