Use a dictionary (or set) as a fast lookup table to reject well-known weak passwords.
You start with:
The Rust editor starts empty, so write the whole program yourself. Begin with the data:
let common = HashSet::from(["password", "123456", "qwerty", "letmein"]);
let password = "qwerty";
Build:
Password: qwerty Common: True Weak: reject
Rules:
- Print
"Password: "followed by the password. - Look the password up in the set
commonand store the result as a boolean. - Print
"Common: "followed by the boolean. Write it asTrueorFalsewith a capital letter, exactly as in the example (your language's own boolean prints differently, so choose the text yourself). - If it is common, print
"Weak: reject"; otherwise print"Strong: accept".
Try other passwords: with Tr0ub4dor the output is
Password: Tr0ub4dor Common: False Strong: accept
Use a
HashSet<&str> and call .contains(password) (returns true if present).
let common = HashSet::from(["password", "123456", "qwerty", "letmein"]);
let password = "qwerty";
println!("Password: {}", password);
let is_common = common.contains(password);
println!("Common: {}", if is_common { "True" } else { "False" });
if is_common {
println!("Weak: reject");
} else {
println!("Strong: accept");
}
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
