码迷,mamicode.com
首页 > 编程语言 > 详细

Python全栈开发第13天

时间:2017-03-27 22:16:01      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:nis   config   系统   username   screen   添加   密码   conf   wro   

#多用户登录                                                                                                                                      



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);

缺点:不能跨平台,开发效率低

 

Python全栈开发第13天

标签:nis   config   系统   username   screen   添加   密码   conf   wro   

原文地址:http://www.cnblogs.com/mojiexiaolong/p/6628443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!