用python制作新用户注册系统_登陆注册系统python初步实现

# 最外面的一层循环,控制系统的结束

while True:

# 根据用户的输入,决定系统是否终止

start = raw_input("You want to (R)egister or (L)ogin or (U)pdate?")

# 判断

if start.lower() == ‘r‘:

while True: #用户可以输入多次username

username = raw_input("Please input your new name:")

sql = "SELECT PASSWORD FROM LOGIN WHERE USERNAME = ‘%s‘" % username

# 查询不到结果返回None

m = cursor.execute(sql)

if m:

print "‘%s‘ has already existed.Please change your name." % username

# 输入错误的话重新循环

continue

else:

password = raw_input("Please input your password:")

Register(username, password)

print "Register sucessfully!"

# while循环中断的唯一途径

break

elif start.lower() == ‘l‘:

while True: # 顶层循环,控制用户名的输入

username = raw_input("Please input your name:")

sql = "SELECT PASSWORD FROM LOGIN WHERE USERNAME = ‘%s‘" % username

m = cursor.execute(sql)

if not m:

print "‘%s‘ doesn‘t exist.Please change your name." % username

continue

else:

# 第二层循环,控制密码输入的次数

for i in range(5):

password = raw_input("Please input your password:")

if Login(username, password):

print "Login sucessfully!"

# 密码正确,及时跳出循环

break

else:

print "The password is wrong.Please input again."

# 循环正常结束的话,执行该else语句

else:

print "You have tried 5 times. The system is locked."

# 跳出顶层循环

break

elif start.lower() == ‘u‘:

while True:

username = raw_input("Please input your name:")

sql = "SELECT PASSWORD FROM LOGIN WHERE USERNAME = ‘%s‘" % username

m = cursor.execute(sql)

if not m:

print "‘%s‘ doesn‘t exist.Please change your name." % username

continue

else:

for i in range(5):

# 先输入原始密码

oldpassword = raw_input("Please input your old password:")

# 原始密码正确的话输入新密码

if Login(username, oldpassword):

password = raw_input("Please input your new password:")

Update(username, password)

print "Update sucessfully!"

# 及时跳出循环

break

else:

print "The password is wrong.Please input again."

else:

print "You have tried 5 times. The system is locked."

break

# 大循环终止条件

else:

break

print "The system is closed!"

cursor.close()

db.close()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值