Python Day 1 ----- simple login verification, python Day 1 -----
-----------------------------------------
Write logon Interface
Requirements: 1. Enter the user name and password
2. The welcome information is displayed after the authentication is successful.
3. Lock after three wrong attempts
--------------------------------------
#coding=utf-8
__author__ = 'wangwc'
import sys,os
Count = 0
Locked = 0
Mark_user = 0
Mark_passwd = 0
# Obtain the path
Def cur_file_dir ():
Path = sys. path [0]
If OS. path. isdir (path ):
Return path
Elif OS. path. isfile (path ):
Return OS. path. dirname (path)
# Print (cur_file_dir ())
Path = cur_file_dir ()
# Print (path)
Path1 = path. replace ("\", '/') + '/'
# Print (path1)
# Path2 = path1 + '/'
# Loop Input
While count <3:
Name = input ("Username:"). strip ()
If len (name) = 0:
Print ("Username can not be empty ....")
Continue
Key = input ("Password:"). strip ()
If len (key) = 0:
Print ("The password can not be empty! Try again ...")
Continue
F = open (path1 + "username.txt", "r ")
Userlist = f. readlines ()
For user in userlist:
If user. strip () = name:
Mark_user = 1
F. close ()
If mark_user = 1:
F = open (path1 + "%s_lock.txt" % (name), "r ")
Locked = int (f. readline (). strip ())
F. close ()
Else:
Print ("Username or Passsord wrong ....")
Break
If locked = 1:
Print ("Sorry, the username had been locked !!! Please call the system administrator ...")
Else:
F = open (path1 + "%s_passwd.txt" % (name), "r ")
Passwd = (f. readline (). strip ())
If passwd. strip () = key:
Mark_passwd = 1
If mark_user = 1 and mark_passwd = 1:
F = open ("%s_count.txt" % (name), "w ")
F. write ("0 ")
F. close ()
Print ("% s, welcome BABY! "% (Name ))
# Input ('Press Enter to exit ')
Else:
F = open ("%s_count.txt" % (name), "r ")
Count = int (f. read (). strip ()))
F. close ()
Count + = 1
F = open ("%s_count.txt" % (name), "w ")
F. write (str (count ))
F. close ()
Print ("Username or password wrong! And the username '% s' has % d more chances to retry! "% (Name, 3-count ))
If (count = 3 ):
Print ("'% s' has been locked !!! "% (Name ))
If OS. path. exists (path1 + "s_s_lock.txt" % (name )):
Fobj = open (path1 + "%s_lock.txt" % (name), "w ")
Fobj. writelines ("1 \ n ")
Else:
Print ("Username or password wrong! ")
Continue