首页 技术 正文
技术 2022年11月17日
0 收藏 966 点赞 4,230 浏览 1566 个字

开始学习python,开始记录。

第一个小程序:登陆系统

功能:1、通过文件名和密码导入用户名和密码~

2、用户输入用户名和密码

3、将用户输入的用户名进行比对,先判断用户名是否在黑名单里面,如果在黑名单里面就直接退出;如果不在黑名单里面就继续输入密码,然后将用户名和密码与正确的用户名密码匹配,匹配通过则显示登陆成功,匹配失败则提示重新输入密码,密码输入错误三次退出系统,锁定用户名,加入黑名单。

用到的知识点:1、文件读写操作。纪要:打开文件,只读用r,打开读且写入内容,用w+或者r+,w+是追加写,但是每次重新打开都会覆盖原来文件的内容。r+是直接在原来的文件                               内容后面追加。

       2、列表基本知识,字典基本知识

       3、导入模块,是输入的密码不可见

源码:

#Author:qcg
import getpass
info = open('/home/me/python-study/20170913/info.txt','r') #导入用户名密码
Blanklist=open('/home/me/python-study/20170913/blanklist.csv','r+')
#username = input("please input username:")
#passwd = input("please input your passqord:")
#创建用户名密码字典
for line in info:
user_list=line.split(',')
i=0
dic_usr={}
while i<len(user_list)/2 -1:
dic_usr[user_list[(2*i)]]=user_list[(2*i+1)]
i+=1
#print (dic_usr)
username = input("please input username:")
for line in Blanklist:
# print (line)
if username in line:
print("sorry,you are forbidden to logn in")
break
count = 0
while count<3:
#passwd = input("please input your password:")
   passwd = getpass.getpass("please input your password:")
if username in dic_usr and dic_usr[username]==passwd: #判断用户名是否在黑名单中,若不在则匹配用户名密码~
print("welcome to logn in")
break
else:
print("please try again~~~")
count+=1
else:
print ("you have try too manay times,byebye")
Blanklist.write(username)
Blanklist.write(',')
Blanklist.close()
info.close()

运行结果:

[root@lmdx6688 20170914]# python3.5 lognin5.py
please input username:123
please input your password:
please try again~~~
please input your password:
please try again~~~
please input your password:
please try again~~~
you have try too manay times,byebye

[root@lmdx6688 20170914]# python3.5 lognin5.py
please input username:qcg
please input your password:
welcome to logn in

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295