Python-based user login system function example, python System Function
This example describes the user logon system function implemented by Python. We will share this with you for your reference. The details are as follows:
There are N, E, and Q options. If Q is selected or interrupted, the system exits. If other options are selected, the user continues to be selected.
#! /Usr/bin/env pythondb ={} def newuser (): prompt = 'login desired: 'While 1: name = raw_input (prompt) if db. has_key (name): prompt = 'name taken, try another: 'Continue else: break pwd = raw_input ('passwd: ') db [name] = pwddef olduser (): name = raw_input ('login: ') pwd = raw_input ('passwd:') passwd = db. get (name) if passwd = pwd: pass else: print 'login incorrect' return print 'welcome back', namedef showmenu (): # main function name prompt = "(N) ew User Login (E) xisting User Login (Q) uitEnter choice: "done = 0 # controller of the control loop while not done: chosen = 0 # controller of the control loop while not chosen: try: choice = raw_input (prompt) [0] response T (EOFError, KeyboardInterrupt): choice = 'q' print '\ nYou picked: [% s]' % choice if choice not in 'neq ': # non-neq continue small loop print 'invalid menu option, try again 'else: chosen = 1 # Skip small loop if choice = 'q ': done = 1 # Jump out of a large loop if choice = 'N': newuser () if choice = 'E': olduser () if _ name _ = '_ main _': showmenu ()
Running result: