forked from abhaysamantni/PythonReview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
68 lines (56 loc) · 2.04 KB
/
login.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# The get_login_name function accepts a first name,
# last name, and ID number as arguments. It returns
# a system login name.
def get_login_name(first, last, idnumber):
# Get the first three letters of the first name.
# If the name is less than 3 characters, the
# slice will return the entire first name.
set1 = first[0 : 3]
# Get the first three letters of the last name.
# If the name is less than 3 characters, the
# slice will return the entire last name.
set2 = last[0 : 3]
# Get the last three characters of the student ID.
# If the ID number is less than 3 characters, the
# slice will return the entire ID number.
set3 = idnumber[-3 :]
# Put the sets of characters together.
login_name = set1 + set2 + set3
# Return the login name.
return login_name
# The valid_password function accepts a password as
# an argument and returns either true or false to
# indicate whether the password is valid. A valid
# password must be at least 7 characters in length,
# have at least one uppercase letter, one lowercase
# letter, and one digit.
def valid_password(password):
# Set the Boolean variables to false.
correct_length = False
has_uppercase = False
has_lowercase = False
has_digit = False
# Begin the validation. Start by testing the
# password's length.
if len(password) >= 7:
correct_length = True
# Test each character and set the
# appropriate flag when a required
# character is found.
for ch in password:
if ch.isupper():
has_uppercase = True
if ch.islower():
has_lowercase = True
if ch.isdigit():
has_digit = True
# Determine whether all of the requirements
# are met. If they are, set is_valid to true.
# Otherwise, set is_valid to false.
if correct_length and has_uppercase and \
has_lowercase and has_digit:
is_valid = True
else:
is_valid = False
# Return the is_valid variable.
return is_valid