Simple Python login Authentication applet

Source: Internet
Author: User

Use Python to write the login authentication applet, the user 3 times in a row password error is locked users.

############# Start ###############

#!/usr/bin/env python

Import OS

Import Sys

#

Os.system (' Clear ')


UserFile = File (' user_id.txt ', ' r+ ')

UserList = []

UserDict = {}



If Os.path.isfile ("User_id.txt"):

Pass

Else

print ' does not define user's files! ‘

Sys.exit


#userfile. ReadLines ()

For Userline in UserFile:

Useritem = Userline.strip ()

#生成系统的用户列表

Value_useritem = Useritem.split (';')

#基本判断添加取出

Value_username = Value_useritem[0].strip ()

VALUE_PASSWD = Value_useritem[1].strip ()

lock_value = Int (value_useritem[-1])

logincount_value = Int (value_useritem[-2])

#生成用户名列表

Userdict[value_username] = {' name ': Value_username, ' pwd ': value_passwd, ' lockcount ': logincount_value, ' locknum ': Lock _value}


Flag = ' Ture '

Counter = 0

While flag:

Username = raw_input (' Please enter user name: ')

USERPASSWD = raw_input (' Please enter password: ')

#判断是否是系统用户

If username not in Userdict.keys ():

print ' This user does not exist! ‘

Break

Elif userdict[username][' locknum '] = = 0 and userdict[username][' Lockcount '] < 3:

if userpasswd = = userdict[username][' pwd '].strip ():

print ' Welcome to landing system!!! ‘

Break

Else

Counter + = 1

userdict[username][' lockcount ') + = 1

UserFile = File (' user_id.txt ', ' w+ ')

For T in Userdict.values ():

Wuserlist = [Str (t[' name ']), str (t[' pwd "), str (t[' lockcount ']), str (t[' locknum '])

#wuserlist = T.values ()

Wuserlist_str = '; '. Join (Wuserlist)

#userfile. Seek (0)

Userfile.write (wuserlist_str + ' \ n ')

If counter >2:

print ' password entered error reached 3 times, exit login. ‘

Break

Else

print ' The user account has been locked! ‘

Sys.exit (' Please contact the administrator to unlock! ‘)

Continue

Userfile.close ()


############# End ###############


Where the format of the User_id.txt is:

User name, password, number of incorrect password, administrator to manually lock the account as follows:

[email protected] day1]# cat User_id.txt

Hejp;123;0;0

Test;456;0;0



User HEJP input three times password error, will display in User_id.txt error password number is 3, at this time the user locked, as long as it changed to 0 can be unlocked.

[email protected] day1]# cat User_id.txt

Hejp;123;3;0

Test;456;0;0


This article is from the "Early bird has the worm to eat" blog, please be sure to keep this source http://hejianping.blog.51cto.com/11279690/1783052

Simple Python login Authentication applet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.