nim-zxcvbn/tests/test_all.nim

44 lines
1.4 KiB
Nim
Raw Permalink Normal View History

2020-10-06 17:54:53 +00:00
import
../zxcvbn
2020-10-16 11:50:32 +00:00
proc passwordEntropy(x: string): float =
result = zxcvbn.passwordEntropy(x)
echo x, " = ", result
# ASCII passwords:
2020-10-06 17:54:53 +00:00
let
a = passwordEntropy "a"
cat = passwordEntropy "cat"
qwerty = passwordEntropy "qwerty"
abracadabra = passwordEntropy "abracadabra"
remixedQwerty = passwordEntropy "qwER43@!"
remixedLongWord = passwordEntropy "Tr0ub4dour&3"
fourWords = passwordEntropy "correcthorsebatterystaple"
longRepeatingSequence = passwordEntropy "1111111111111111111111111111111"
strongPassword = passwordEntropy "ds10s81*&NQLPAfg9*21Ke}|w(*&121=_(11e2"
doAssert strongPassword > fourWords
doAssert fourWords > remixedLongWord
doAssert remixedLongWord > remixedQwerty
doAssert remixedQwerty > abracadabra
2020-10-07 12:43:59 +00:00
doAssert remixedQwerty > qwerty
doAssert remixedQwerty > cat
doAssert remixedQwerty > a
doAssert remixedQwerty > longRepeatingSequence
2020-10-06 17:54:53 +00:00
2020-10-16 11:50:32 +00:00
# UTF-8 Passwords:
let
bulgarianPassword = passwordEntropy("парола")
bulgarianRepeatingSeq = passwordEntropy("яяяяяя")
japanesePassword = passwordEntropy("パスワード")
japaneseRepeatingSeq = passwordEntropy("パパパパパ")
chinesePassword = passwordEntropy("密碼")
chineseFourWords = passwordEntropy("正確的馬電池釘書釘")
doAssert bulgarianPassword > bulgarianRepeatingSeq
doAssert japanesePassword > japaneseRepeatingSeq
doAssert chineseFourWords > chinesePassword
2020-10-06 17:54:53 +00:00
echo "SUCCESS"
2020-10-16 11:50:32 +00:00