-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_debug.rs
More file actions
71 lines (60 loc) · 1.9 KB
/
test_debug.rs
File metadata and controls
71 lines (60 loc) · 1.9 KB
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
fn calculate_strength(password: &str) -> u8 {
let mut score = 0u8;
// 1. Length scoring
let length_score = match password.len() {
0..=7 => (password.len() * 3) as u8,
8..=11 => 25,
12..=15 => 32,
16..=19 => 38,
_ => 40,
};
score += length_score;
eprintln!("After length: {}", score);
// 2. Character variety
let has_lower = password.chars().any(|c| c.is_ascii_lowercase());
let has_upper = password.chars().any(|c| c.is_ascii_uppercase());
let has_digit = password.chars().any(|c| c.is_ascii_digit());
let has_symbol = password.chars().any(|c| !c.is_alphanumeric());
let variety_count = [has_lower, has_upper, has_digit, has_symbol]
.iter()
.filter(|&&x| x)
.count();
let variety_score = match variety_count {
1 => 5,
2 => 12,
3 => 20,
4 => 30,
_ => 0,
};
score += variety_score;
eprintln!("After variety: {}", score);
// 4. Common pattern penalties
let password_lower = password.to_lowercase();
let common_patterns = [
"password", "qwerty", "asdfgh", "zxcvbn",
"letmein", "welcome", "login", "admin",
"123456", "111111", "123123",
];
for pattern in &common_patterns {
if password_lower.contains(pattern) {
eprintln!("Found common pattern: {}", pattern);
score = score.saturating_sub(25);
break;
}
}
// 5. Bonus for length > 16
if password.len() > 16 {
score += 5;
}
// 6. Bonus for unique characters
let unique_chars: std::collections::HashSet<char> = password.chars().collect();
if unique_chars.len() as f64 / password.len() as f64 > 0.7 {
score += 5;
}
eprintln!("Final score: {}", score);
score.max(0).min(100)
}
fn main() {
let result = calculate_strength("MyPass123!");
eprintln!("Result: {}", result);
}