用户登陆接口
来源:互联网 发布:醋昆布 淘宝 编辑:程序博客网 时间:2024/04/29 17:34
需求:
1、输入用户名、密码
2、认证通过欢迎
3、三次失败锁定用户
一:
#!/usr/bin/env python
import os #导入模块
account_file = 'account.txt' #用户文件
lock_file = 'lock.txt' #锁定用户文件
for i in range(3):
username = raw_input("username:").strip() #消除空格,包括\n\r\t
password = raw_input("password:").strip()
if len(username) !=0 and len(password) !=0: #判定非空
f = file(account_file)
loginSuccess = False #置标志位
for line in f.readlines():
line = line.split() #切
if username == line[0] and password ==line[1]:
# user and passwd are correct
print "Welcome %s login my system" % username
loginSuccess = True
break
if loginSuccess is True: # login success
break
else:
continue
else:
f = file(lock_file)
f.write('%s\n' % username) #写入锁定文件
f.close()
二:
#!/usr/bin/env python
import os
account_file = 'account.txt'
lock_file = 'lock.txt'
#put account in a list
f = file(account_file)
acount_list = f.readlines()
f.close()
while True:
#put locked user into a lock list
f = file(lock_file)
lock_list = []
for i in f.readlines():
line = i.strip('\n') #rm \n
lock_list.append(line ) #追加
f.close()
print lock_list
loginSuccess = False
username = raw_input('user:').strip()
if username in lock_list:
print "sorry"
break
for line in acount_list:
line = line.split()
if line[0] == username: #correct name
for i in range(3):
password = raw_input('passwd:').strip()
if password == line[1]: # correct pd
print "Welcome %s login my system!@" % username
loginSuccess = True
break
else:
f = file(lock_file,'a')
f.write('%s\n' %username)
f.close()
print "Enter 3 times of wrong passwd,going to lock %s" % username
if loginSuccess == True:break # jump out of for top loop
if loginSuccess == True:break # jump out of while loop
- 用户登陆接口
- PYTHON自学手册--用户登陆接口
- 用postman调试接口跳过用户登陆的方式
- 用户登陆
- 用户登陆
- 用户登陆
- 用户登陆
- 用户登陆
- 用户登陆
- 接口登陆
- bos webservice接口后登陆用户会覆盖前用户的context的解决方法
- ASIHTTPRequest用户登陆:重复用户登陆问题解决
- ASIHTTPRequest用户登陆:重复用户登陆问题解决
- 用户接口
- 用户接口
- 用户接口
- 用户接口
- netbeans 用户登陆.
- C++成员函数的存储方式
- html5手机页面 点击事件
- 程序员的困境
- Android中字体加粗
- Jquery EasyUI 弹出“加载中。。。”效果
- 用户登陆接口
- Android之xml
- android平台上编程实现事件注入 part1
- ImportError: No module named redis
- 简易入手SUI
- Cocoa框架类之间继承关系
- mysql emoji表情支持
- pdf_down_py
- 黑马程序员——JAVA基础----集合框架(二)