zoukankan      html  css  js  c++  java
  • python练习——moudule01——模拟登陆

    模拟登陆:
    1. 用户输入帐号密码进行登陆
    2. 用户信息保存在文件内
    3. 用户密码输入错误三次后锁定用户

    #! /usr/bin/env python
    # -*- coding: utf-8 -*-
    # __author__ = "macel"
    # Date: 2017/4/27

    with open('userdata.txt', 'r') as data,open('lock.txt', 'r') as locked:
    flag = False
    List= []
    while flag == False :
    username = input('please input your username:')
    #将光标放到data的开始位置
    data.seek(0)
    for line in data:
    if line.strip().split(':')[0] == username:
    flag = True
    count = 0
    while flag:
    locked.seek(0)
    for line in locked:
    if line.strip() == username:
    print('sorry,your accout has been locked!')
    exit()
    data.seek(0)
    password = input('please input your password:')
    for line in data:
    name = line.strip().split(":")[0]
    passwd = line.strip().split(":")[1]
    List.append(username)
    if name==username and passwd==password :
    print('Welcome!')
    flag= False
    exit()
    elif name==username and passwd!=password :
    count += 1
    if count==3:
    with open('lock.txt', 'a') as locked:
    locked.write(username)
    locked.write(' ')
    print('your account has been locked!')
    flag = False
    break
    else:
    print('wrong password,please try again!')
  • 相关阅读:
    【leetcode刷题笔记】Best Time to Buy and Sell Stock II
    【leetcode刷题笔记】Reverse Integer
    JAVA中的NIO(二)
    标准I/O
    margin的理解
    JAVA中的NIO(一)
    IO模型
    linux网络命令
    linux用户管理命令
    linux中的帮助命令
  • 原文地址:https://www.cnblogs.com/Macal/p/6854037.html
Copyright © 2011-2022 走看看