一.英雄联盟登陆
import random
while True:
print("\t\t\t英雄联盟商城界面\n")
print("~*"*25)
print("\t\t\t1.用户登录\n")
print("\t\t\t2.用户注册\n")
print("\t\t\t3.退出系统\n")
print("~*"*25)
a = int(input('请输入你的选项1-3:'))
if a == 1:
username =input('请输入你的用户名:')
password = input('请输入你的密码:')
if username=='幼杀快发歌吧' and password == '8888':
print('恭喜您,登陆成功')
while True:
print("\t\t\t英雄联盟商城界面\n")
print("~*" * 25)
print("\t\t\t1.进入英雄商店\n")
print("\t\t\t2.休闲小游戏\n")
print("\t\t\t3.退出登陆\n")
print("~*" * 25)
choice = input('请输入您的选择:')
if choice == '1':
print('新款皮肤2.8折,您需要支付50')
num = int(input('请你输入您要购买的数量:'))
sum1 = num * 50
print('您购买的皮肤,需要支付的金额是:', sum1)
pay = int(input('请支付商品需要的金额:'))
if pay == sum1:
print('恭喜,购买成功')
else:
print('抱歉,支付金额有问题,请重新支付')
elif choice == '2':
print('成功进入休闲小游戏')
words = ('python', 'jumble', 'easy', 'difficult', 'answer', 'continue', 'phone', 'position', 'game')
right = 'Y'
print("欢迎参加猜单词游戏!")
while right == 'Y' or right == 'y':
word = random.choice(words)
correct = word
new_word = ''
while word:
pos = random.randrange(len(word))
new_word += word[pos]
word = word[:pos] + word[(pos + 1):]
print("你要猜测的单词为:", new_word)
guess = input("请输入你的答案:")
count = 1
while count < 5:
if guess != correct:
guess = input("输入的单词错误,请重新输入:")
count += 1
else:
print("输入的单词正确,正确单词为:", correct)
break
if count == 5:
print("您已猜错5次,正确的单词为:", correct)
right = input("是否继续,Y/N:")
else:
break
else:
print('用户名或密码错误,请重新登陆,按任意键继续:')
elif a == 2:
phone = input('请输入你要注册的手机号:')
b = len(phone)
if b == 11:
c = input('请输入短信验证码:')
d = len(c)
if d == 6:
password1 = input('请输入密码:')
password2 = input('请再次输入密码:')
if password1 == password2 and len(password1) <= 8:
print('恭喜你,注册成功')
else:
print('两次密码输入不一致或设置密码过短,请重新注册')
else:
print('短信验证码输入有误,请重新输入')
else:
print('手机输入错误,请重新输入')
elif a == 3:
break
二.md5盐值登陆注册页面
import hashlib
import sys
import pickle
users = []
slat = '%$#%&*%%##'
def init():
global users
users = pickle.load(open('登陆.txt', 'rb'))
print(users)
def save_data():
save_users = pickle.dumps(users)
f = open('登陆.txt', 'wb')
f.write(save_users)
print('保存完成')
f.close()
def password_md5(password):
md5 = hashlib.md5(password.encode('utf-8'))
md5.update(slat.encode('utf-8'))
return md5.hexdigest()
def main():
print('\t\t 1.用户注册')
print('\t\t 2.用户登录')
print('\t\t 3.查询所有用户信息')
print('\t\t 4.退出系统')
print('~*'* 20)
choice = input('请输入您要操作的选项:')
return choice
def register():
username = input('请输入你的用户名称:')
password = input('请输入你的用户密码:')
if username == None or username.strip() == ' ':
print('用户名不能为空')
return
if password == None or password.strip() == ' ' or len(password) < 3:
print('密码长度不能小于3')
return
if exits_user(username):
print('对不起,该用户已经存在,请重新输入')
return
user = {}
user['username'] = username
user['password'] = password_md5(password)
users.append(user)
print(users)
print('开始保存用户')
save_data()
def exits_user(username):
for i in users:
if i.get('username') == username:
return True
return False
def is_login(username, password):
for i in users:
if i.get('username') == username and i.get('password') == password:
print('登陆成功')
return True
return False
def login():
username = input('请输入用户名:')
password = input('请输入用户密码:')
password = password_md5(password)
if is_login(username, password):
print('恭喜你登陆成功')
else:
print('对不起,登陆失败,请重新登陆')
init()
while True:
choice = main()
if choice == '1':
print('用户注册')
register()
elif choice == '2':
print('用户登陆')
login()
elif choice == '3':
print('显示所有用户')
print(users)
else:
print('程序正常退出')
sys.exit(0)
运行结果:
|