Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 61 additions & 15 deletions userpw.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,81 @@ def newuser():
continue
else:
break
pwd = raw_input('passwd: ')#用户名合格后,要求输入密码
logt=time()#获取时间戳
db[name]=[pwd,logt]#把密码和时间组成列表存到字典,共享一个键
pwd = raw_input('passwd: ')
logt=time()
db[name]=[pwd,logt]

def olduser():
name=raw_input('login: ')
pwd=raw_input('passwd: ')
if name in db:#检测是否是老用户
if pwd == db.get(name)[0]: #获取老用户密码与输入密码比较
print 'welcome back',name #显示欢迎信息
if name in db:
if pwd == db.get(name)[0]:
print 'welcome back',name
print 'You lasttime logged in at:',ctime(db[name][1])
#显示上次登录的时间戳
current=time()#获取当前时间
delta=current-db[name][1]#求上次登录与现在时间的时间差
current=time()
delta=current-db[name][1]
if delta<=14400: #判断是否在4小时内
print 'You already logged in 4 hours period!'

else:#若时间差不在四小时之内
else:
logt=time()#获取当前时间
db[name][1]=logt #把密码和时间组成列表存到字典,共享一个键,更新时间戳
else: #密码错误
db[name][1]=logt #把密码和时间组成列表存到字典,共享一个键
else:
print 'login incorrect'

else: #不是老用户
print 'login incorrect'
else:
print 'login incorrect'

def deluser():
Getuserpwd()
c=raw_input('del a user,its name:')
if c in db.keys():
del db[c]
print 'After del:'
Getuserpwd()
else:
print 'Wrong choose!'

def Getuserpwd():
if db:
for name in db:
print 'name:',name,'pwd:',db[name][0]
else:
print 'No usr!'

def management():
prompt = """
(D)el a user
(G)et all user and pwd
(Q)uit

Enter choice: """

done = False
while not done:
chosen = False
while not chosen:
try:
choice = raw_input(prompt).strip()[0].lower()
except (EOFError, KeyboardInterrupt):
choice = 'q'
print '\nYou picked: [%s]' % choice

if choice not in 'gdq':
print 'invalid menu option, try again'
else:
chosen = True

if choice == 'q': done = 1
if choice == 'd': deluser()
if choice == 'g': Getuserpwd()


def showmenu():
prompt = """
(N)ew User Login
(E)xisting User Login
(M)anagement
(Q)uit

Enter choice: """
Expand All @@ -56,14 +101,15 @@ def showmenu():
choice = 'q'
print '\nYou picked: [%s]' % choice

if choice not in 'neq':
if choice not in 'neqm':
print 'invalid menu option, try again'
else:
chosen = True

if choice == 'q': done = 1
if choice == 'n': newuser()
if choice == 'e': olduser()
if choice == 'm': management()

if __name__ == '__main__':
showmenu()