python 登入小程序
import xlrd,xlwt,operator,sys,os
from xlutils.copy import copy
'''
已excel作为数据库,输入用户名后先查询是否是锁定账号,如果不是在查询是否是注册过的用户(3次)
注册过的用户输入密码,查询密码是否正确,不正确重新输入,最大次数是3次,超过3次了就锁定该用户名。
'''
path =sys.argv[0]
book = xlrd.open_workbook(os.path.dirname(path)+"\hello world.xls")
sheet0=book.sheet_by_name("账号密码对应表")
sheet1=book.sheet_by_name("锁定账号")
sheet_nrows=sheet1.nrows
nrows = sheet0.nrows
count=1
cols = sheet1.col_values(0)
flag2 = True
while count<=3:
flag=True
index=1
name=input("pls input your name:")
if name in cols:
print ("your id is locked")
flag2 = False
break
while index<nrows:
cell_value1 = sheet0.cell_value(index,0)
if operator.eq(cell_value1,name)==True:
ctype=sheet0.cell(index,1).ctype
if ctype == 2:
password_value1=str(int(sheet0.cell_value(index,1)))
flag=False
break
else:
password_value1=str(sheet0.cell_value(index,1))
flag=False
break
index+=1
if index==nrows:
print ("your ID is unregistered!")
if flag==False:
print ("welceme,your ID is registered!")
break
count+=1
flag1=False
if flag==False:
num=1
while num<=3:
password=input("pls input your password:")
if operator.eq(password,password_value1)==True:
print ("welcome,your password is right!")
flag1=True
break
else:
if num != 3:
print ("password error,try %d time"%num)
else:
print ("try %d time,your ID should locked!"%num)
num+=1
if flag1==False and flag2==True:
wb=copy(book)
ws=wb.get_sheet(1)
ws.write(sheet_nrows,0,name)
wb.save(os.path.dirname(path)+"\hello world.xls")
浙公网安备 33010602011771号