A program Introduction
1.1 File Distribution
Login_user.jpg Flowchart Information
README.txt
login_main_v1.1.py Main Program
user_config.conf configuration file
Flow chart:
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/5C/wKioL1dSgS7QhNkvAAGYzFmv3t4581.jpg-wh_500x0-wm_3 -wmp_4-s_2538692698.jpg "title=" login_user.jpg "alt=" Wkiol1dsgs7qhnkvaagyzfmv3t4581.jpg-wh_50 "/>
README.txt
# # # #by cw#####
login_main_v1.1.py
#2016-06-04
Program Run Instructions:
1. Run the program login_main.py
2. Enter the user name and password, Input_check () Check the user input is correct, the user name and password can not be empty, password at least 6 digits, if not conform to the specification, return to the login interface can be entered
3. If qualified, then execute Login_check (), check whether the user is locked, if locked, then exit, if not locked, continue to the next step
4. Continue to check user Login_passwd_check (), login username is correct, if correct, give welcome interface
5. If the user name and password is not correct, execute Login_limit_check () then return to the login screen, counter plus 1, if the counter is greater than 3 times, then lock the user and exit
Subsequent extensible content:
Registering users to MySQL
Lock users can store to Memcached/redis
Web Presentation Sub-function
Continue to improve according to the following comprehensive exercises
###### #end readme.txt###############
User_config.conf
#username, Password,status,lock_count
Chenwei, Chenwei, n,0
chenwei2,chenwei,y,0
chenwei3,chenwei,y,0
Two-coded
The specific code below, some implementations are not simple enough, subsequent second version optimization
#/bin/python#coding=utf-8#by cw#2016-06-03import osuser_conf_file= ' D:\chenwei\data\user_config.conf ' user_conf_tmp= ' D:\chenwei\data\user_config_tmp.conf ' Count_limt=0def welcome_main (): print " welcome to python world!!!!!!! by cw "Def read_config_file (file,username): ' :p aram file: profile :p aram username: user name entered :return: read user profile, return username, lock status ' fn=open (file) user_conf= " status=" count= ' passwd= ' for line in fn: if line.split (', ') [0].strip () == username: #根据用户名去查找, take care to remove the space &nBsp; user_conf=line.split (', ') [0] #返回用户名 passwd=line.split (', ') [1] #返回密码 status=line.split (', ') [2] #返回状态 count=line.split (', ') [3] #返回次数 fn.close () return (User_conf,passwd,status,count) # return status Def input_check (USERNAME,PASSWD): flag=true if len (username) == 0: print ' the username is null,please Input againt!!! ' flag=false if len (passwd) == 0: print ' the passwd is null,please&Nbsp;input againt!!!! ' flag=false if len (passwd) < 6: print "The passwd length is not enough! " Flag=False return Flagdef Login_lock_check (status): if status == ' Y ': return False #the user don ' t locked else: return true #the user lockeddef lock_usered (file,file_tmp,username): fn = open (file) fn_tmp = open (file_tmp, ' a ') new_line = [] for line in&nBsp;fn.readlines (): #读取配置文件的每一行 if Line.split (', ') [0].strip () == username: new_line.append ("%S&NBSP;," % username) new_line.append ("%S&NBSP;," % line.split (', ') [1].strip ()) new_line.append (' N, ') new_line.append ('%s \n ' % line.split (', ') [3].strip ()] fn_tmp.writelines (new_line) continue fn_tmp.writelines (line) fn.close () fn_tmp.close () os. remove (file) os.rename (file_tmp, file) while true: Config_list= ' name = raw_input (' please input your name: ') passwd = raw_input (' please input your password: ') if input_check (NAME,PASSWD) == False : #检查用户名和密码的规范性 continue else: config_list=read_config_file (User_conf_file,name) #返回配置文件里面的内容 if login_lock_check (config_list[2]): #返回用户状态 print "the user is locked" exit () else: if name == config_list[0] and passwd == config_list[1]: welcome_main () exit () else: Count_limt = Count_limt + 1 if Count_limt == 1: print ' The username or password is not right,you maybe try two!!! ' &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP;COUNT_LIMT&NBSP;==&NBSP;2: print ' The username or password is not right,you maybe&nbSp;try one!!! ' if count_limt >= 3: lock_usered ( User_conf_file,user_conf_tmp,name) print "user locked!!!" exit ()
This article is from the "Ruffian Cook actor" blog, please be sure to keep this source http://chenwei.blog.51cto.com/32183/1786067
Python Comprehensive Practice-User login