-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserPassSimple.py
More file actions
129 lines (111 loc) · 4.49 KB
/
UserPassSimple.py
File metadata and controls
129 lines (111 loc) · 4.49 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import re
import sys
import hashlib
import webbrowser
users = {}
def get_user(username):
return users.get(username)
def is_valid_email(email):
pattern = r'^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$'
match = re.fullmatch(pattern, email)
if match:
return True
else:
return False
def login_user():
username = input("Enter your username: ").lower()
password = input("Enter your password: ").lower()
user = get_user(username)
if user is None:
print("Invalid username or password")
return
hashed_password = hashlib.sha256(password.encode()).hexdigest()
if hashed_password == user["password_hash"]:
print("Login successful!")
print()
print("Welcome back to UserPass " + username + "!")
post_login = input("(What would you like to view today? (Weather, Stock Market, Shoe Styles, or Clothing Styles) ")
if post_login.lower() == "weather":
weather_location = input("(What area would you like to view (Los Angeles, New York, Miami)")
if weather_location.lower() == "los angeles":
webbrowser.open("https://weather.com/weather/tenday/l/b1d7089dcff056d6907ce58c458f2a32932387f1854af523080c6c79e2678e66")
elif weather_location.lower() == "new york":
webbrowser.open("https://weather.com/weather/tenday/l/New+York+NY+USNY0996:1:US")
elif weather_location.lower() == "miami":
webbrowser.open("https://weather.com/weather/tenday/l/864c2346b3a36fcc8c5d5a73b0651ea44f9968ff6c6b445530eeb9cef734ae58")
else:
sys.exit()
elif post_login.lower() == "stock market" or post_login.lower() == "stocks":
webbrowser.open("https://finance.yahoo.com/")
elif post_login.lower() == "shoes":
webbrowser.open("https://stylecaster.com/shoe-trends-2023/")
elif post_login.lower() == "clothes":
webbrowser.open("https://www.yahoo.com/lifestyle/best-2023-fashion-trends-shop-140000909.html")
else:
sys.exit()
else:
print("Invalid username or password")
if not is_valid_email(emailsetup):
print("Please enter a valid email address.")
return
hashed_password = hashlib.sha256(password.encode()).hexdigest()
setup = input("Welcome to UserPass! Lets set up your account. Enter 'setup' to continue ")
if setup.lower() == "login":
login_user()
sys.exit()
emailsetup = input("Please enter your email address: ")
while not is_valid_email(emailsetup):
print("Please enter a valid email address")
emailsetup = input("Please enter your email address: ")
enteremail2 = input("Please re-enter your email address: ")
while True:
if emailsetup != enteremail2:
print("Please enter your email as you did in the first step")
print()
enteremail2 = input("Please enter your email again: ")
else:
emailcheck = input("You entered " + emailsetup + " is this correct?")
if emailcheck.lower() == "yes":
print("Great! This is saved")
break
elif emailcheck.lower() != "yes":
print("\033[1mPlease re-enter your email\033[0m")
enteremail2 = ""
print()
print()
print("Now that you set up your preferred account settings, we will get some personalization")
print()
print()
desired_username = input("Enter a desired username no longer than 10 characters: ")
if len(desired_username) > 11:
print("Invalid Input")
else:
check = input("You entered" +' '+ desired_username +' '+ "is this correct?")
for counter in range(1):
if check.lower() == "yes":
print("Great! This is saved in the system")
if check.lower() != "yes":
print("Re-run program and try again")
sys.exit
while True:
desired_password = input("Enter a desired password no longer than 10 characters: ")
if len(desired_password) > 11:
print("Invalid Input")
else:
if desired_password == desired_username:
print("Your password cannot be the same as your username")
continue
check = input("You entered" +' '+ desired_password +' '+ "is this correct?")
if check.lower() == "yes":
hashed_password = hashlib.sha256(desired_password.encode()).hexdigest()
users[desired_username] = {
"username": desired_username,
"password_hash": hashed_password
}
print("Your account has been created successfully!")
print("Please login to continue")
login_user()
break
elif check.lower() != "yes":
print("Re-run program and try again")
break