Skip to content

Commit

Permalink
Fix inconsistent scoring in bruteforce scoring mechanism
Browse files Browse the repository at this point in the history
Our implementation of saturating exponentiation was incorrect
Closes #15
  • Loading branch information
Josh Holmer committed Jan 4, 2018
1 parent 543a668 commit 3a04d01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**Version 0.6.3 (unreleased)**
- Refactor handling of strings to use streaming of characters. This brings zxcvbn closer to working on UTF-8 inputs.
- Fix an issue that would cause bruteforce scores to be too low (https://github.com/shssoichiro/zxcvbn-rs/issues/15)

**Version 0.6.2**
- Upgrade dependencies and fix linter warnings
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ mod tests {
fn test_zxcvbn() {
let password = "r0sebudmaelstrom11/20/91aaaa";
let entropy = zxcvbn(password, &[]).unwrap();
assert_eq!(entropy.guesses, 473_471_216_704_000);
assert_eq!(entropy.guesses_log10, 14);
assert_eq!(entropy.score, 4);
assert!(!entropy.sequence.is_empty());
Expand All @@ -161,4 +162,22 @@ mod tests {
let entropy = zxcvbn(password, &[]).unwrap();
assert_eq!(entropy.score, 4);
}

#[test]
fn test_issue_15_example_1() {
let password = "TestMeNow!";
let entropy = zxcvbn(password, &[]).unwrap();
assert_eq!(entropy.guesses, 372_010_000);
assert_eq!(entropy.guesses_log10, 8);
assert_eq!(entropy.score, 3);
}

#[test]
fn test_issue_15_example_2() {
let password = "hey<123";
let entropy = zxcvbn(password, &[]).unwrap();
assert_eq!(entropy.guesses, 1_010_000);
assert_eq!(entropy.guesses_log10, 6);
assert_eq!(entropy.score, 2);
}
}
2 changes: 1 addition & 1 deletion src/scoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl Estimator for BruteForceEstimator {
let mut guesses = BRUTEFORCE_CARDINALITY;
let token_len = m.token.chars().count();
if token_len >= 2 {
for _ in 2..token_len {
for _ in 2..(token_len + 1) {
guesses = guesses.saturating_mul(BRUTEFORCE_CARDINALITY);
}
}
Expand Down

0 comments on commit 3a04d01

Please sign in to comment.