zoukankan      html  css  js  c++  java
  • day1-登录

    1、流程图

    2、代码

     1 #!/usr/bin/env python
     2 #-*- coding:utf-8 -*-
     3 #Author: Tony Chiu
     4 #Blog:http://www.cnblogs.com/tonychiu
     5 #Github:https://github.com/qiujichun
     6 '''
     7 match.txt
     8     user1:pass1
     9     user2:pass2
    10     user3:pass3
    11     user4:pass4
    12 locked.txt
    13     u1
    14     u2
    15     u3
    16 '''
    17 import sys
    18 retry_count = 0
    19 
    20 #指定账户、锁定信息路径
    21 account_file = (r'match.txt')
    22 locked_file = (r'locked.txt')
    23 
    24 # 输入用户名
    25 username = input("Insert your name:")
    26 
    27 # 判断用户是否锁定
    28 lockinfo = open(locked_file, "r")
    29 for line in lockinfo.readlines():
    30     if username == line.strip():
    31         print("Your account %s is be locked"%username)
    32         sys.exit()
    33 lockinfo.close()
    34 
    35 #匹配用户名和密码
    36 for i in range(3):
    37     retry_count = retry_count+1
    38     password = input("Insert password:")
    39     userinfo = open(account_file, "r")
    40     for line in userinfo.readlines():
    41         User, Pass = line.strip().split(':')
    42         if username == User and password == Pass:
    43             print("Success!")
    44             sys.exit()
    45         else:
    46             continue
    47     userinfo.close()
    48 
    49     #尝试密码超过3次将锁定账户
    50     if retry_count == 3:
    51         print("Too many attempts,%s will be locked...."%username)
    52         lockinfo = open(locked_file, "a")
    53         lockinfo.write('
    ' + username)
    54         lockinfo.close()
    55         sys.exit()
    View Code

    3、测试

    3.1输入已被锁定的用户

    1 Insert your name:u1
    2 Your account u1 is be locked
    3 
    4 Process finished with exit code 0
    View Code

    3.2输入正确信息

    1 Insert your name:user1
    2 Insert password:pass1
    3 Success!
    4 
    5 Process finished with exit code 0
    View Code

    3.3输出错误密码3次

    1 Insert your name:user1
    2 Insert password:
    3 Insert password:
    4 Insert password:
    5 Too many attempts,user1 will be locked....
    View Code
  • 相关阅读:
    USACO Milk2 区间合并
    Codeforces 490B Queue【模拟】
    HDU 3974 Assign the task 简单搜索
    HDU 5119 Happy Matt Friends(2014北京区域赛现场赛H题 裸背包DP)
    Cin、Cout 加快效率方法
    POJ 1159 回文LCS滚动数组优化
    POJ 2479 不相交最大子段和
    POJ 1458 最长公共子序列 LCS
    在阿里最深刻的,还是职场之道给我的震撼
    精细化
  • 原文地址:https://www.cnblogs.com/tonychiu/p/5872254.html
Copyright © 2011-2022 走看看