Python-based user login system function example, python System Function

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.