The Python database is used as the mailbox registration system!

Source: Internet
Author: User
#! /Usr/bin/ENV python2.7 #-*-coding: UTF-8-*-# file: w7.py # Date: 2013-7-18 # Author: wangyuimport reimport sqlite3 "when you feel sad for some days, you must experience some different things that will make you more powerful, thank you for the hardships and thoughts the world has given me. "start to learn regular expressions" email Registration System "class e_mail: def xuanze (self, xuanxian): If (xuanxian = 'Z'): Print "Welcome to register" Elif (xuanxian = 'D'): Print "Welcome to" else: print "input error, enter" Return xuanxian def zhuce (Self): A = true conn = sqlite3.connect ('/home/WY /Py/test/bin/e_mail ') Conn. isolation_level = none # This is the transaction isolation level. By default, only the required commit can be used to modify the database. If it is set to none, it is automatically submitted for each modification. Otherwise, it is "" C = Conn. cursor () c.exe cute (''' create table if not exists zhuce7 (username TXT frimary key, password txt, liuyan nchar (256 ))''') c.exe cute (''' select username, password from zhuce7; ''') while a = true: username = raw_input ("Enter your registered account :") # print "Nima" m = Re. match (R "^ ([a-zA-Z0-9] + [-\ |.]?) + [A-zA-Z0-9] @ ([0-9a-za-z] + (-[a-z0-9A-Z] + )? \.) + [A-Za-Z] {2,} $ ", username); # print m if M: D = C. fetchall () I = 0 for (S, B) in D: While true: If S = Username: Print "you registered" + STR (username) + "the account has been registered. Please register" username = raw_input ("Enter your registered account:") # print "wocao" else: a = false break else: print "your mailbox" + STR (username) + "format error. Please enter" username = raw_input ("Please enter your mailbox again") While true: password = raw_input ("enter your password:") Pwd = Re. match (R "^ ([a-zA-Z0-9])", password) if (PWD and (LEN (password) <9): Print "the password is too short or does not conform to the format" else: break while true: password1 = raw_input ("enter your password again :") if (password! = Password1): Print "the two inputs are inconsistent. Please re-enter" else: break while true: If (PWD and (LEN (password) <9 )): print "the password is too short or does not conform to the format" else: break while true: YZM = int (raw_input ("Please enter your verification code: 123 + 123 =?: ") If YZM! = 246: Print "Incorrect verification code. Please enter" else: Break print "again. The email is successfully registered. Keep your password safe." c.exe cute (''' insert into zhuce7 (username, password) values (?,?) ''', (Username, password) Conn. commit () # automatically submit and insert data c. close () def denglu (Self): username1 = raw_input ("Enter the username:") password1 = raw_input ("enter the password :") conn = sqlite3.connect ('/home/WY/Py/test/bin/e_mail') Conn. isolation_level = none d = Conn. cursor () d.exe cute (''' select username, password from zhuce7; ''') up = D. fetchall () Count = 0 A = Len (up) While true: If (up [count] [0] = username1 ): print up [count] [0] # the output of this loop is A binary table, so it is better to directly verify the data in the binary table if (password1 = up [count] [1]): print "Login successful" # start to leave a message Ce = int (raw_input ("whether to send: Send, enter: 1 \ n if not send, enter: 2 \ n ")) if Ce = 1: liuyan = STR (raw_input ("please write your sending content here:") # Ceshi = liuyan. decode ('utf-8 '). encode ('gbk') d.exe cute (''' update zhuce7 set liuyan =? Where username =? ''', (Liuyan, username1) Break else: Return 0 else: Print "the password is incorrect, please note that the case "break COUNT = count + 1 A = A-1 if (a = 0): Print" account is not registered, please re-enter "break return 0if _ name __= = '_ main _':" I just found that the error tolerance system of python is a finite array, for example, when I enter an option in the test file and the number of error messages exceeds a certain number, the program "" APP = e_mail () will be terminated () print "++ Thank you for using ++" While true: try: xuanxian = raw_input ("select \ n registration input: Z \ n logon input: d \ n "). strip () [0]. lower () random t (eoferror, keyboardinterrupt): xuanxian = C if xuanxian not in 'zd': Print "the key value you entered is [% s] and the input is invalid, enter "% xuanxian else: Break app again. xuanze (xuanxian) if (xuanxian = 'Z'): app. zhuce () Elif (xuanxian = 'D'): app. denglu ()

I have not fixed several bugs! The reason is that I cannot use try well, so I still need to improve it!

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.