#!/usr/bin/env python # -*- coding:utf-8 -*- # Author "Sniper" import getpass import os ### Registry Account 注册用户,将用户数据存入文件中 print("Welcome to the Registry System!\n\n\n") username = input("Please Input Your UserName:") password = input("Please Input Your Password:") password2 = input("Please Verify Your Password:") if password == password2 : userfile = open("username.txt", "w+", encoding="UTF-8") passfile = open("password.txt", "w+", encoding="UTF-8") userfile.write(username) passfile.write(password) userfile.flush() passfile.flush() userfile.seek(0) passfile.seek(0) userfile.close() passfile.close() else: print("Your Password Is Not Matched ,Check Your Input!") exit() cls = os.system("cls") ####Login System 登录用户,判断登录信息是否正确 usr = open("username.txt") psd = open("password.txt") UserName = usr.read() PassWord = psd.read() count = 3 while True : print("++++++++++++++++++++++++++++++++++++++") print("+++ Welcome To The Alauda System +++") print("++++++++++++++++++++++++++++++++++++++") yourusername = input("Please input your username:") yourpassword = input("Please Input your password:") if UserName == yourusername and PassWord == yourpassword : print("Welcome {name} login ...".format(name=username)) break else : print("Please input the true username or password !\n") print("You lose 1 chance , Now you have {counts} chances\n".format(counts=count -1)) count -= 1 if count == 0 : print("Uh-huh !!! You have been used up Your chances. Your account will be locked!!!\n") exit() usr.close() psd.close()
本文介绍了一个简单的用户注册和登录系统实现方法,通过Python脚本完成用户输入验证,并将用户名及密码存储于本地文件中,同时具备基本的错误提示功能。
976

被折叠的 条评论
为什么被折叠?



