Your users passwords were all stole in the Yahoo! hack, and it turns out they have been lax in creating secure passwords.  Create a function that checks their new password (passed as a string) to make sure it meets the following requirements:


Between 8 - 20 characters

Contains only the following characters: (and at least one character from each category): uppercase letters, lowercase letters, digits, and the special characters !@#$%^&*?




Return "valid" if passed or else "not valid"

Difficulty: EASY
Starter code: def check_password(s):
	

Solutions:
import re

def check_password(s):
	if re.search('^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\\d)(?=.*?[!@#$%^&*?])[a-zA-Z\\d!@#$%^&*?]{8,20}$', s):
		return 'valid'
	else:
		return 'not valid'


import re
PATTERN = re.compile('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?\\d)(?=.*?[!@#$%^&*?])[A-Za-z\\d!@#$%^&*?]{8,20}$')

def check_password(s):
	return 'valid' if PATTERN.match(s) else 'not valid'


from re import sub

def check_password(string):
	reduced = sub('[a-z]', 'a', sub('[A-Z]', 'A', sub('[0-9]', '0', sub('[!@#$%^&*?]', '!', string))))
	return 'valid' if 8 <= len(string) <= 20 and set(reduced) == set('aA0!') else 'not valid'


def check_password(s):
	c1 = 8 <= len(s) <= 20
	c2 = any([i.isupper() for i in s])
	c3 = any([i.islower() for i in s])
	c4 = any([i.isdigit() for i in s])
	c5 = any([i for i in s if i in '!@#$%^&*?'])
	c6 = not any([i for i in s if i not in '!@#$%^&*?' and (not i.isupper()) and (not i.islower()) and (not i.isdigit())])
	return 'valid' if c1 and c2 and c3 and c4 and c5 and c6 else 'not valid'


from re import search

def check_password(s):
	return 'valid' if bool(search('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*?])[\\w!@#$%^&*?]{8,20}$', s)) else 'not valid'


import re

def check_password(s):
	if len(s) > 20 or len(s) < 8:
		return 'not valid'
	a1 = bool(re.search('[A-Z]', s))
	a2 = bool(re.search('[a-z]', s))
	a3 = bool(re.search('\\d', s))
	a4 = bool(re.search('[!@#$%^&*?]', s))
	a5 = bool(re.search('^[A-Za-z!@#$%^&*?\\d]*$', s))
	return 'valid' if a1 * a2 * a3 * a4 * a5 else 'not valid'


import re

def check_password(s):
	return 'valid' if re.search('^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*?])[A-Za-z0-9!@#$%^&*?]{8,20}$', s) else 'not valid'


from string import digits as D, ascii_lowercase as L, ascii_uppercase as U
S = '!@#$%^&*?'

def check_password(s):
	return 'valid' if 8 <= len(s) <= 20 and all((c in D + L + U + S for c in s)) and any((c in D for c in s)) and any((c in L for c in s)) and any((c in U for c in s)) and any((c in S for c in s)) else 'not valid'


def check_password(s):
	import re
	chars = '!@#$%^&*?1234567890qazwsxedcrfvtgbyhnujmiklopQAZWSXEDCRFVTGBYHNUJMIKLOP'
	sp = '[!@#$%^&*?]'
	a = '[a-z]'
	if len(s) in range(8, 21):
		for c in s:
			if c not in chars:
				return 'not valid'
	else:
		return 'not valid'
	if all((re.search(sp, s), re.search('\\d', s), re.search(a, s), re.search(a.upper(), s))):
		return 'valid'
	else:
		return 'not valid'