文件目录下有两个文件

user_name.txt

lock_file.txt

实际中可以读数据库里的信息

代码如下

 #encoding = utf-8
import sys user_file = 'user_name.txt'
lock_file = 'lock_file.txt' retry_count = 0
retry_limit = 3 while retry_count < retry_limit:
username = raw_input('\033[32;1mUsername:\033[0m')
lock_check = file(lock_file)
for line in lock_check.readlines():
       line = line.split()
if username == line[0]:
sys.exit('%s is locked' % username) passwd = raw_input('\033[32;1mPassword:\033[0m') f = file(user_file,'rb')
match_flag = False
for line in f.readlines():
   user,password = line.strip('\n').split()
if username == user and passwd == password:
match_flag = True
break
f.close()
if match_flag == False:
   print 'User unmatched'
retry_count += 1
else:
  print 'Welcome login Learning python'
  sys.exit(0)
else:
print 'Your account is lock'
f = file(lock_file,'ab')
f.write(username+'\n')
f.close()

python一个简单的登录的更多相关文章

  1. Appium+python 一个简单的登录测试实例

    # coding=utf-8 from appium import webdriver import time import unittest import os import HTMLTestRun ...

  2. Python 实现简单的登录注册界面

    Python 实现简单的登录注册界面 注意:编写代码之前需要导入很重要的包 import tkinter as tk import pickle from tkinter import message ...

  3. python+tkinter 简单的登录窗口demo

    一个简单的登录窗口布局,可以用于日常快速搭建一个简单的窗口类. from tkinter import * import tkinter.messagebox class LoginUi: def _ ...

  4. jmeter 压力测试(一)一个简单的登录

    写在最前面,之所以记录这个最最简单的http的登录,是因为捣鼓了一天,真的是找错也找不错了,后来请教的同事,重新写了一个ok了,最后发现竟然是因为[http信息头]写的有问题,简直是!!醉了 如下,这 ...

  5. 第四章 .net core做一个简单的登录

    项目目标部署环境:CentOS 7+ 项目技术点:.netcore2.0 + Autofac +webAPI + NHibernate5.1 + mysql5.6 + nginx 开源地址:https ...

  6. python -----一个简单的小程序(监控电脑内存,cpu,硬盘)

    一个简单的小程序 用函数实现!~~ 实现: cpu 使用率大于百分之50 时  ,  C 盘容量不足5 G 时, 内存 低于2G 时. 出现以上其中一种情况,发送自动报警邮件! 主要运用 到了两个 模 ...

  7. Python—一个简单搜索引擎索引库

    因为课业要求,搭建一个简单的搜索引擎,找了一些相关资料并进行了部分优化(坑有点多) 一.数据 数据是网络上爬取的旅游相关的攻略页面 这个是travels表,在索引中主要用到id和url两个字段. 页面 ...

  8. python小练习,利用dict,做一个简单的登录。

    '''利用字典实现登录'''users=[{'username':'jerry','pwd':'123456'},{'username':'tom','pwd':'1'}] def login(use ...

  9. python 做一个简单的登录接口

    # -*- conding :utf-8 -*-# File Name: homewoe# Create Date: 2019/11/20 / 9:15# Change Activity: 2019/ ...

随机推荐

  1. linux 下部署 kafka

    参考文章 http://www.cnblogs.com/sunxucool/p/4459020.html http://www.cnblogs.com/oftenlin/p/4047504.html ...

  2. setAttribute()和getAttibute(),getParameter()

    request.setAttribute("key",value)方法给主键设置一个值, request.getAttribute("key")方法从上述设置的 ...

  3. RRDTool 三个命令的使用

    要了解rrdtool如何使用就要先从rrd的数据存储方式开始,rrdtool就是为了操作这个数据库的工具,抄来下面一段文字解释. 0x01 什么是rrd数据库 所谓的“Round Robin” 其实是 ...

  4. 2016/9/21 leetcode 解题笔记 395.Longest Substring with At Least K Repeating Characters

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  5. UIColor 分类 16进制转 RGB

    .h #import <UIKit/UIKit.h> @interface UIColor (WJ) + (UIColor *)colorWithWJString:(NSString *) ...

  6. treeMap and treeSet

    TreeSet:如果要对对象进行排序,对象类要实现Comparable接口! TreeMap:如果要对对象进行排序,对象类要实现Comparable接口! 下面是我自己写的小程序主要传输对象 publ ...

  7. UWP深入学习五: 传感器与搜索、共享及链接

    Responding to motion and orientation sensors: Quickstart: Responding to user movement with the accel ...

  8. [更新中]并发和并行(Concurrency and Parallelism)

    书籍的简称: CSPPSE: Computer System: a programmer's perspective Second Edition 术语并发是一个通用的概念, 指同时具有多个活动的系统 ...

  9. 那些年我们学过的PHP黑魔法

    那些年我们学过的PHP黑魔法 提交 我的评论 加载中 已评论 那些年我们学过的PHP黑魔法 2015-04-10 Sco4x0 红客联盟 红客联盟 红客联盟 微信号 cnhonker_huc 功能介绍 ...

  10. Keil的标题“礦ision3" 的改变(转)

    MDK 的标题显示成 “礦ision3",前面的这个不是u而是一个希腊字母“缪”,在中文显示中出现问题,半个汉字. 可以使用如下方法取消. 一: 光标问题 Keil uv3 中会出现光标定位 ...