創建以用戶登錄程序:保存用戶的用戶名與密碼
新建用戶時,判斷用戶是否已經存在,若存在則報錯;
登錄系統是,確保用戶名存在於系統中,密碼正確,有三次機會,超過三次報錯冷卻
#!/usr/bin/env python
# coding:utf-8
name = ['root','linux']
passwd = ['redhat']
def select():
create=raw_input("輸入你要建立的用戶名:")
if create in name:
print "用戶已存在"
else:
name.append(create)
print '用戶建立成功'
def denglu():
for i in (1,6):
name1 = raw_input('請輸入帳號:')
passwd1 = raw_input('輸入密碼:')
if (name1 in name and passwd1 in passwd):
print 'welcome to user manager system'
exit(0)
else:
print '用戶名或密碼錯誤'
print ('密碼錯誤三次,冷卻時間三分鐘')
def showmenu():
pro = """
歡迎使用xxx登陸器
新建用戶(S/s)
登陸系統(D/d)
Enter choice:"""
while True:
choice = raw_input(pro).lower()
if choice == 's':
select()
elif choice == 'd':
denglu()
else:
print "input s/d"
showmenu()