#多用户登录
import getpass #引用getpass
import os #引用os
import configparser #引用配置文件操作的库
count = 0
count_other = 0
while True:
if os.path.exists('./user.conf'): #判断user.conf用户是否存在
user_name = input("please input your username:") #输入用户名
user_pass = getpass.getpass("please input your password:") #输入密码
cp = configparser.ConfigParser() # 加载现有配置文件
cp.read("./user.conf")
li = cp.get('user', 'user').split(',') #将用户名放入列表li中
if user_name in li: #判断用户是否在列表中
password = cp.get( user_name , 'password')
status = int(cp.get( user_name , 'status'))
if password == user_pass:
if status == 3 :
print("Your username is locked!Please contact your administrator ")
break
else:
print("Welcome to my system!!!")
break
else:
print("You input the username or password is wrong ,please try agin!!")
status = int(status) + 1
cp.set(user_name , 'status',str(status) )
with open('user.conf', 'w') as fw:
cp.write(fw)
if status == 3:
print("Your username is locked!Please contact your administrator ")
break
else:
print("You input the username or password is wrong ,please try agin!!")
count_other = count_other + 1
if count_other == 3 :
break
continue
else:
conf = configparser.ConfigParser()
# 写入配置文件
conf.add_section('user') #添加section
# 添加值
conf.set('user', 'user', 'jimmy,aaa,bbb')
conf.add_section('jimmy')
conf.set('jimmy', 'password', 'aaa')
conf.set('jimmy', 'status', '0')
conf.add_section('aaa')
conf.set('aaa', 'password', 'aaa')
conf.set('aaa', 'status', '0')
conf.add_section('bbb')
conf.set('bbb', 'password', 'bbb')
conf.set('bbb', 'status', '0')
# 写入文件
with open('./user.conf', 'w') as fw:
conf.write(fw)
Python是一门什么类型的语言:
编译型语言,把明文的代码执行前,先转成二进制,在执行,这个过程就叫编译;(c,c++,go)
特点:运行效率高;依赖编译平台,linux操作系统跟cpu的交互结构与Windows不是完全一样的(例如linux:print_to_console,windos:print_to_screen);
缺点:不能跨平台,开发效率低