python编写一个邮箱系统,python数据库做成邮箱的注册系统!

#! /usr/bin/env python2.7

# -*- coding:utf-8 -*-

#File:w7.py

#Date:2013-7-18

#Author:wangyu

import re

import sqlite3

"""当你感到有些日子先当难过的时候,那你一定经历一些不一样的东西,这些东西会让你变的更加强大,谢谢世界给我的苦难和思考"""

"""开始学习正则表达式"""

"""邮箱注册系统"""

class e_mail:

def xuanze(self,xuanxian):

if (xuanxian=='z'):

print "欢迎注册"

elif (xuanxian=='d'):

print "欢迎登录"

else:

print "输入错误请重新输入"

return xuanxian

def zhuce(self):

a=True

conn=sqlite3.connect('/home/wy/py/test/test/bin/e_mail')

conn.isolation_level=None#这个就是事物隔离级别,默认是自己需要的commit才能修改数据库,设置为None则自动每次修改都提交,否则为""

c=conn.cursor()

c.execute('''create table if not exists zhuce7(username txt FRIMARY KEY,

password txt,

liuyan NCHAR(256)

)

''')

c.execute('''select username,password from zhuce7;''')

while a==True:

username=raw_input("请输入您的注册帐号:")

# 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 "您注册的"+str(username)+"帐号已经被注册,请你重新注册"

username=raw_input("请输入您的注册帐号:")

# print "wocao"

else:

a=False

break

break

else:

print "你的邮箱"+str(username)+"格式错误,请重新填写"

username=raw_input("请重新填写您的邮箱")

while True:

password=raw_input("请输入您的密码:")

pwd=re.match(r"^([a-zA-Z0-9])",password)

if (pwd and (len(password)<9)):

print "密码过短,或者不符合格式"

else:

break

while True:

password1=raw_input("请再次输入您的密码:")

if (password!=password1):

print "两次输入不一致,请重新输入"

else:

break

while True:

if (pwd and (len(password)<9)):

print "密码过短,或者不符合格式"

else:

break

while True:

yzm=int(raw_input("请输入您的验证码:123+123=?:"))

if yzm!=246:

print "验证码错误请重新输入"

else:

break

print "邮箱注册成功,注意保管自己的密码"

c.execute('''insert into zhuce7(username,password)

values(?,?)''',(username,password)

)

conn.commit()

# 自动提交插入数据

c.close()

def denglu(self):

username1=raw_input("请输入用户名:")

password1=raw_input("请输入密码:")

conn=sqlite3.connect('/home/wy/py/test/test/bin/e_mail')

conn.isolation_level=None

d=conn.cursor()

d.execute('''select username,password

from zhuce7;

''')

up=d.fetchall()

count =0

a=len(up)

while True:

if (up[count][0]==username1):

print up[count][0]

# 这个循环输出的是一个二元表,所以直接验证二元表里面的数据就好

if ( password1==up[count][1]):

print "登录成功"

#开始留言

ce=int(raw_input("是否发信:发信请输入:1\n不发请输入:2\n"))

if ce==1:

liuyan =str(raw_input("请在此处写下您的发件内容:"))

# ceshi=liuyan.decode('utf-8').encode('gbk')

d.execute('''update zhuce7 set liuyan=? where username=?

''',(liuyan,username1)

)

break

else:

return 0

else:

print "密码不正确,请注意大小写"

break

count=count+1

a=a-1

if (a==0):

print "帐号没有注册,请重新输入"

break

return 0

if __name__=='__main__':

"""刚刚在测试的时候发现,python的容错系统是一个有限数组,比如我测试文件输入选项时,提示错误次数超过一定次数,就会终止程序"""

app=e_mail()

print "++++++++++++++感谢您的使用++++++++++++++"

while True:

try:

xuanxian=raw_input("请选择:\n注册输入:z\n登录输入:d\n").strip()[0].lower()

except(EOFError,KeyboardInterrupt):

xuanxian=c

if xuanxian not in 'zd':

print "您输入的键值为[%s]输入不合法,请重新输入"%xuanxian

else:

break

app.xuanze(xuanxian)

if (xuanxian=='z'):

app.zhuce()

elif(xuanxian=='d'):

app.denglu()这个其中有几个bug,我没有处理!原因是我不能很好的使用try,所以还需要改进一下!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值