Skip to content

Commit c4a14fb

Browse files
authored
Merge pull request #25 from 1Password/ivan/push-llkxlypknpsr
Update zxcvbn Upstream PR async-graphql#1671
2 parents 1d052a0 + 7467e21 commit c4a14fb

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ futures-channel = { version = "0.3.30", optional = true }
113113
lru = { version = "0.16", optional = true }
114114
serde_cbor = { version = "0.11.2", optional = true }
115115
sha2 = { version = "0.10.8", optional = true }
116-
zxcvbn = { version = "2.2.2", optional = true }
116+
zxcvbn = { version = "3.1.0", optional = true }
117117
handlebars = { version = "6.3", optional = true }
118118
schemars = { version = "1", optional = true }
119119

src/validators/min_password_strength.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
use zxcvbn::{ZxcvbnError, zxcvbn};
1+
use zxcvbn::{Score, zxcvbn};
22

33
use crate::{InputType, InputValueError};
44

55
pub fn min_password_strength<T: AsRef<str> + InputType>(
66
value: &T,
77
min_score: u8,
88
) -> Result<(), InputValueError<T>> {
9-
match zxcvbn(value.as_ref(), &[]) {
10-
Ok(password_strength) => {
11-
if password_strength.score() < min_score {
12-
Err("password is too weak".into())
13-
} else {
14-
Ok(())
15-
}
16-
}
17-
Err(ZxcvbnError::BlankPassword) => Err("password is too weak".into()),
18-
_ => Err("error processing password strength".into()),
9+
let min_score = match min_score {
10+
0 => Score::Zero,
11+
1 => Score::One,
12+
2 => Score::Two,
13+
3 => Score::Three,
14+
_ => Score::Four,
15+
};
16+
17+
let score = zxcvbn(value.as_ref(), &[]).score();
18+
19+
if score < min_score {
20+
Err("password is too weak".into())
21+
} else {
22+
Ok(())
1923
}
2024
}
2125

0 commit comments

Comments
 (0)