Skip to content

Instantly share code, notes, and snippets.

@GuillermoPena
Created May 28, 2014 09:11
Show Gist options
  • Save GuillermoPena/72b00dd2700f0b2e44bb to your computer and use it in GitHub Desktop.
Save GuillermoPena/72b00dd2700f0b2e44bb to your computer and use it in GitHub Desktop.
CheckIO - Home Challenge 3 : House Password
# CheckIO - Home Challenge 3 : House Password
# http://checkio.org
# Stephan and Sophia forget about security and use simple passwords for everything.
# Help Nikola develop a password security check module.
# The password will be considered strong enough if its length is greater than or equal to 10 symbols,
# it has at least one digit, as well as containing one uppercase letter and one lowercase letter in it.
# The password contains only ASCII latin letters or digits.
# Input: A password as a string (Unicode for python 2.7).
# Output: Is the password safe or not as a boolean or any data type that can be converted and processed as a boolean. In the results you will see the converted results.
# Precondition:
# re.match("[a-zA-Z0-9]+", password)
# 0 < len(password) ≤ 64
def checkio(data):
# Checking Length
length=len(data)
if (length < 10):
return False
# Checking characters
digit=False
upper=False
lower=False
i=0
while (i<length and (not(digit) or not(upper) or not(lower))):
char=data[i]
if (char.isupper()):
upper=True
elif (char.isdigit()):
digit=True
elif (char.islower()):
lower=True
i+=1
# Final validation
return (digit and upper and lower)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio('A1213pokl') == False, "1st example"
assert checkio('bAse730onE4') == True, "2nd example"
assert checkio('asasasasasasasaas') == False, "3rd example"
assert checkio('QWERTYqwerty') == False, "4th example"
assert checkio('123456123456') == False, "5th example"
assert checkio('QwErTy911poqqqq') == True, "6th example"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment