用户登录验证小程序~


db ={} def newuser(): prompt = 'login desired:' while True: name = raw_input(prompt) if db.has_key(name): prompt = 'name taken,try another.' continue else: break pwd = raw_input('passwd:') db[name] = pwd def olduser(): name = raw_input('login') pwd = raw_input('passwd') passwd = db.get(name) i = 0 while i <3: if passwd == pwd: print 'welcome back',name break else: print 'passwd wrong ,try again.' i = i + 1 def showmenu(): prompt = ''' (N)ew User (E)xiting User Login (Q)quit enter choice ''' done = False while not done : chose = False while not chose: try: choice = raw_input(prompt).strip()[0].lower() except (EOFError,KeyboardInterrupt): choice = 'q' print '\nYou picked"[%s]' % choice if choice not in 'neq': print 'invalid option, try again.' elif choice == 'n': newuser() chosen = True done = True elif choice == 'e': olduser() chosen = True done = True else : break if __name__ == '__main__': showmenu()

 

posted @ 2016-06-22 11:04  你好呀。  阅读(1198)  评论(0编辑  收藏  举报