ABSP, Ch 7, Practice Project #1

My solution to the Practice Project #1 in Chapter 7 of the excellent book “Automate the Boring Stuff with Python” (ABSP)

#! usr/bin/env python3
# by lorenzo - 21/07/2017
# Test if a given password is "strong"
# A password is said to be strong if it's at least eight characters long,
# contains both uppercase and lowercase characters, and has at least one digit

import re

regexEight = re.compile(r'\w{8,}') # password at least eight characters long
regexLower = re.compile(r'[a-z]+') # at least one lowercase characters
regexUpper = re.compile(r'[A-Z]+') # at least one uppercase character
regexDigit = re.compile(r'\d+')    # at least one digit

print("Password tester: type a password and I will tell you if it's strong")
password = input()
if regexEight.search(password) and regexLower.search(password) and regexUpper.search(password) and regexDigit.search(password):
    print('The password ' + password + ' is strong.')
    print('the password ' + password + ' is weak.')

Comments about the code are welcome.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s