# 最外面的一层循环,控制系统的结束
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()