Check a password with two rules: it must have at least 8 characters and contain at least one digit.
You start with:
password := "Secret99"
Build:
Length: 8 Has digit: True Strong
Rules:
- Print
"Length: "followed by the number of characters. - Loop through each character to set a boolean flag
hasDigit, which starts asfalseand becomestruewhen a digit is seen. - Print
"Has digit: "followed by the flag. Write it asTrueorFalsewith a capital letter, exactly as in the example (your language's own boolean prints differently, so choose the text yourself). - If the length is at least 8 and
hasDigitistrue, printStrong; otherwise printWeak. - Use
strconv.Itoa(n)to turn a number into text before joining it to a string. - The helper
boolText(b)returns"True"or"False"for a boolean.
Try other passwords: with abcdefgh the output is
Length: 8 Has digit: False Weak
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
