Đây là chương trình đầu tiên của tôi mà tôi đã tự viết. Có điều gì tôi có thể cải thiện?
Có một vài điều vẫn cần được thêm vào, chẳng hạn như:
- Xác nhận mật khẩu trong khi đăng ký
- Thêm một cách để lấy mật khẩu bị lãng quên bằng ID email
Nhưng chức năng của nó là hoàn thành tối thiểu. Có điều gì mà các chuyên gia thấy rằng tôi có thể cải thiện hoặc thay đổi trong chương trình này không?
Tập tin chính
import Functions
start = ""
while start == "" :
start = input["Type S to Create a Account and Type L to login into your Account: "]
Username_List = Functions.username_list[]
if start == "S" or start == "s":
username = input["Enter a Username: "]
for user in Username_List:
while user == username:
username = input["Username Exists, Try Again: "]
password = input["Enter a Password: "]
email_adress = input["Enter Email ID: "]
Functions.sign_up[username,password,email_adress]
start = ""
elif start == "L" or start == "l":
login_username = input["Enter Your Username: "]
while login_username not in Username_List:
print['Username Does not Exist.']
user_input = input["Type R to retry and X to exit: "]
if user_input == "r" or user_input == "R":
login_username = input["Enter Your Username: "]
if user_input == "x" or user_input == "X":
break
if login_username not in Username_List:
print["Invalid Session \n\n"]
start = ""
else:
no = Username_List.index[login_username]
password = input["Enter a Password: "]
Functions.extract_matrix[login_username,password,no]
start = ""
else:
print["Invalid Session \n\n"]
start = ""
Functions.py
import csv
def sign_up[username,password,email]:
filename = "signup_info.csv"
data = [[username,password,email]]
# writing to csv file
with open[filename, 'a', newline=''] as csvfile:
# creating a csv dict writer object
writer = csv.writer[csvfile]
# writing data rows
writer.writerows[data]
def username_list[]:
username_list=[]
with open['signup_info.csv','r'] as f:
for line in f :
username_list.append[line.split[','][0]]
return username_list
def extract_matrix[username,password,no]:
password_list = []
email_list = []
username_list = []
with open['signup_info.csv','r'] as f:
for line in f:
password_list.append[line.split[','][1]]
for line in f:
email_list.append[line.split[','][2]]
for line in f:
username_list.append[line.split[','][0]]
data_password = password_list[no]
while password != data_password:
print['Incorrect Password']
user_input = input ["Type R to retry and X to exit: "]
if user_input == "r" or user_input == "R":
password = input["Enter Password: "]
if user_input == "x" or user_input == "X":
break
if password == data_password:
print["Login Successful"]
else:
print["Invalid Session \n\n"]
-1
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi muốn có một chương trình cho phép người dùng tạo tài khoản nếu họ không có, nhưng nếu họ làm điều đó cho phép họ đăng nhập và kiểm tra tên người dùng và mật khẩu với các tên họ khi họ tạo tài khoản. Mã này hoạt động để đăng ký, nhưng không phải cho phần đăng nhập / kiểm tra nếu người đó đã tạo tài khoản.
import os.path
if os.path.exists["username"]:
login[]
else:
make_account[]
def make_account
filename = ["username"];
with open [filename, "w"] as f:
f.write [input["Enter a username: "]];
filename = ["password"];
with open [filename, "w"] as f:
f.write [input["Enter a password: "]];
def login
username = input["Enter your username: "]
password = input["Enter your password: "]
check[]
def check
if username == open["username"].read[]: and
passsword == open["password"].read[]:
print["Successful login"]
else:
print['Incorrect']
hỏi ngày 31 tháng 7 năm 2017 lúc 15:05Jul 31, 2017 at 15:05
4
Thử cái này:
import os.path
if os.path.exists["username"]:
login[]
else:
make_account[]
def make_account[]:
filename = ["username"];
with open [filename, "w"] as f:
f.write [input["Enter a username: "]];
filename = ["password"];
with open [filename, "w"] as f:
f.write [input["Enter a password: "]];
def login[]:
username = input["Enter your username: "]
password = input["Enter your password: "]
check[]
def check[]:
if username == open["username"].read[] and passsword == open["password"].read[]:
print["Successful login"]
else:
print['Incorrect']
Đã trả lời ngày 31 tháng 7 năm 2017 lúc 15:19Jul 31, 2017 at 15:19
1
import os.path
def login[]:
def make_account[]:
filename = "username"
with open[filename, "w"] as f:
f.write[input["Enter a username: "]]
filename = "password"
with open[filename, "w"] as f:
f.write[input["Enter a password: "]]
def login[]:
def check[]:
if username == open["username"].read[] and\
password == open["password"].read[]:
print["Successful login"]
else:
print['Incorrect']
username = input["Enter your username: "]
password = input["Enter your password: "]
check[]
if os.path.exists["username"]:
login[]
else:
make_account[]
S.B
9.3617 Huy hiệu vàng19 Huy hiệu bạc40 Huy hiệu đồng7 gold badges19 silver badges40 bronze badges
Đã trả lời ngày 28 tháng 3 lúc 1:36Mar 28 at 1:36
1