python学习 登陆验证

 1 #!/usr/bin/env python
 2 #-*- coding=utf-8 -*-
 3 #----------------导入模块------------------------------
 4 import os
 5 import sys
 6 
 7 #----------------设置账户密码------------------------------
 8 user_name = ['root', 'hyg', 'None']
 9 user_passwd = ['123qwe', '123123', 'None']
10 file_list = '/home/hyg/py/file/user_db.txt'
11 #----------------登陆验证------------------------------
12 def user_login ():
13   i = 0
14   def passwd_login ():
15     while True:
16       global NAME_INPUT
17       NAME_INPUT = raw_input("请输入您的用户名:").strip()
18       if len(NAME_INPUT) == 0:
19         print "用户名不能为空!"
20         continue 
21       else:
22         break
23     return
24 
25   passwd_login()
26 
27   while True:
28     if i < 3:
29       passwd_input = raw_input("请输入您的密码:")
30       if len(passwd_input) == 0:
31         print "密码不能为空!"
32         continue
33 
34       elif NAME_INPUT not in user_name:
35         print("您输入的密码有误,请您重新输入!")
36         i += 1
37         continue
38 
39       else:
40         if passwd_input == user_passwd[user_name.index(NAME_INPUT)]:
41           print("您好%s,欢迎登陆员工信息查询系统!") % NAME_INPUT
42           break
43         else:
44           print("密码有误,请重新输入您的密码")
45           i += 1
46           continue
47         break
48       break
49     else:
50       print "您的密码输错3次请您重新核对账号和密码!"
51       i = 0
52       passwd_login()
53       continue
54 user_login()
55 print("OK")
原文地址:https://www.cnblogs.com/hygs/p/5266081.html