fork(1) download
  1. from re import*
  2. n,p=map(input,["Username: ","Password: "])
  3. c,U,L=lambda x:len(split("[%s]"%x,p)),"A-Z","a-z"
  4. print(["OK.","Nope."][any([8>len(p)>12,2>c(U)>9,2>c(L)>9,3>c(U+L),match(U+L,p),2>c("0-9"),n in p,n[::-1]in p,any(c(x)>3 for x in p),len(findall("(.)\\1",p))>1,c(' ^=&#,;"><[|)')>1])])
  5.  
  6. # --- end of solution ---
  7.  
  8. # length output:
  9. print("\nThis python 3 code is {} bytes long.".format(len("""
  10. from re import*
  11. n,p=map(input,["Username: ","Password: "])
  12. c,U,L=lambda x:len(split("[%s]"%x,p)),"A-Z","a-z"
  13. print(["OK.","Nope."][any([8>len(p)>12,2>c(U)>9,2>c(L)>9,3>c(U+L),match(U+L,p),2>c("0-9"),n in p,n[::-1]in p,any(c(x)>3 for x in p),len(findall("(.)\\1",p))>1,c(' ^=&#,;"><[|)')>1])])
  14. """.strip())))
  15.  
  16. # Additional debug output:
  17. print("\nDebug output: check results (True -> password failed this check)")
  18. print("length 8-12: ", 8>len(p)>12)
  19. print("uppercase 1-8: ", 2>c(U)>9)
  20. print("lowercase 1-8: ", 2>c(L)>9)
  21. print("letters 2+: ", 3>c(U+L))
  22. print("1st is letter: ", bool(match(U+L,p)))
  23. print("has digits: ", 2>c("0-9"))
  24. print("not name: ", n in p)
  25. print("not rev. name: ", n[::-1]in p)
  26. print("max 3 same: ", any(c(x)>3 for x in p))
  27. print("max 1 pair: ", len(findall("(.)\\1",p))>1)
  28. print("no special: ", c(' ^=&#,;"><[|)')>1)
  29.  
Success #stdin #stdout 0.03s 9984KB
stdin
JOE.smith
JOE!smith123
stdout
Username: Password: OK.

This python 3 code is 291 bytes long.

Debug output: check results (True -> password failed this check)
length 8-12:  False
uppercase 1-8:  False
lowercase 1-8:  False
letters 2+:  False
1st is letter:  False
has digits:  False
not name:  False
not rev. name:  False
max 3 same:  False
max 1 pair:  False
no special:  False