【发布时间】:2016-05-09 03:29:10
【问题描述】:
我正在为类做简单的数据库,但密码功能有问题。我不明白为什么每次都要求设置密码。我认为问题在于阅读是否已经在基础中,但我不知道如何解决它。
import shelve
global base,pas
global magazine_base
def load_data():
global base
global magazine_base
magazine_base = shelve.open('magazine_base')
if magazine_base.has_key('base'):
base = magazine_base['base']
if not base:
base = []
else:
base = []
magazine_base['base'] = base
def enterpass():
global base,pas
epas=raw_input("Enter password to acces database")
for entry in base:
while True:
if epas == entry['pas']:
break
else:
print "Password incorrect"
def password():
global base,pas
global magazine_base
load_data()
is_firstopen = True
if 'pas' in base:
is_firstopen = False
enterpass()
if is_firstopen:
while True:
pas=raw_input("This is the first start of database.\nPlease enter the password, min. 5 characters: ")
if len(pas)>5:
break
base += [{'pas':pas}]
magazine_base['base'] = base
magazine_base.close()
print "Password set"
else:
print "Password too short"
【问题讨论】: