循环判断以及文件的使用--练习1

本文介绍了一个简单的用户注册和登录系统实现方法,通过Python脚本完成用户输入验证,并将用户名及密码存储于本地文件中,同时具备基本的错误提示功能。
#!/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()

 

转载于:https://www.cnblogs.com/Sniper-tech-share/p/9857829.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值