username = input("Please enter your username: ")
username0 = username
username1 = username.find(" ")
username2 = username.isdigit
username3 = len(username)
password = input("Please enter your password: ")
password1 = len(password)
password2 = password.find("!, @, #, $, %, ^, &, *, (, ), -, _, +, =, `, ~, {, [, }")
password3 = password.find("], |, :, ;, ', ,, ., ?, /")
if username1 == -1:
pass
elif username1 >= 0:
print("Your username can not contain spaces.")
breaker1 = 1
if username2:
pass
elif not username2:
print("Your username can not contain numbers.")
breaker2 = 2
if username3 > 12:
print("Your username can not be more than 12 characters.")
elif username3 <= 12:
pass
breaker3 = 3
if password1 > 12:
print("Your password can not be more than 12 characters.")
elif password1 <= 12:
pass
if password2 == -1:
pass
elif password2 >= 0:
print("Your password can not contain symbols.")
elif password3 == -1:
pass
elif password3 >= 0:
print("Your password can not contain symbols.")
password4 = password.replace("a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q", "*")
password5 = password.replace("r, s, t, u, v, w, x, y, z","*")
print("Your username is " + username + " and your password is " + password + ".")
print(username2)
我正在尝试制作一个代码,可以获取您的用户名和密码,记住它,然后能够将您锁定或让您进入,无论您是否输入了正确的用户名和密码。
我尝试重写某些区域,我尝试使用我用来编码的网站提供的ai,我尝试分解if语句(这就是“Breaker1 = 1”的意思,我想也许if的字符串语句扰乱了 pass 命令)。请记住,我对编码还比较陌生,大约一周前我才开始学习 python。我希望有人能对此有所了解?谢谢!
这里有一些代码,其中包含一些您可以使用的有用函数。它允许您注册用户名和密码并将其存储在同一目录中的文本文件中。这样它会在代码停止运行后保存。这一点也不安全,但作为一个初学者项目,它是有效的。
def StoreUsernamePassword(username,password):
#make sure there are no spaces
username = username.strip()
#make sure there are no numbers in the username
if any(char.isdigit() for char in username):
print("Username cannot contain numbers")
return
#make sure username is less than 12 characters
if len(username) > 12:
print("Username cannot be more than 12 characters")
return
#make sure password doesn't have symbols
if any(not char.isalnum() for char in password):
print("Password cannot contain symbols")
return
#make sure password is at most 12 characters
if len(password) > 12:
print("Password cannot be more than 12 characters")
return
with open("credentials.txt", "w") as f:
f.write(f"{username}\n{password}")
def ReadUsernamePassword():
with open("credentials.txt", "r") as f:
username = f.readline().strip()
password = f.readline().strip()
return username, password
def login():
username, password = ReadUsernamePassword()
input_username = input("Enter username: ")
input_password = input("Enter password: ")
if input_username == username and input_password == password:
print("Login successful")
else:
print("Login failed")
def register():
username = input("Enter username: ")
password = input("Enter password: ")
StoreUsernamePassword(username, password)
print("Registration successful")