-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ_029_100xp_the_password_validator.nim
More file actions
59 lines (42 loc) · 1.13 KB
/
Q_029_100xp_the_password_validator.nim
File metadata and controls
59 lines (42 loc) · 1.13 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
import strutils
# This challenge is tedious, I just want to get through it ASAP
proc isValid(password: string): bool =
let
cleaned = password.strip
hasT = 'T' in cleaned
hasAmpersand = '&' in cleaned
if len(cleaned) < 6 or len(cleaned) > 13:
return false
if hasT or hasAmpersand:
return false
var
hasUpper = false
hasLower = false
hasNumber = false
for c in cleaned:
if not hasUpper:
hasUpper = c.isUpperAscii
if not hasLower:
hasLower = c.isLowerAscii
if not hasNumber:
hasNumber = c.isDigit
return hasUpper and hasLower and hasNumber
when isMainModule:
block tooShort:
doAssert not isValid("")
doAssert not isValid("12345")
block tooLong:
doAssert not isValid("tooooooooooooo loooooooooooooooong")
block noUpper:
doAssert not isValid("passw0rd")
block noLower:
doAssert not isValid("PASSW0RD")
block noNumber:
doAssert not isValid("Password")
block hasT:
doAssert not isValid("Passw0rdT")
block hasAmpersand:
doAssert not isValid("Passw0rd&")
block valid:
doAssert isValid("Passw0rd")
echo "All tests passed"