Python program 1 "Login Interface"

Source: Internet
Author: User

Writing the Login interface

--Enter user name and password

--Show welcome message after successful authentication

--locked three times after the wrong time

Version-1

-------------------------------

Account_file = ' Account.txt '

Lock_file = ' Lock.txt '

For I in range (3):

Username = raw_input ("Username:"). Strip ()

Password = raw_input ("Password:"). Strip ()

If Len (username)!=0 and len (password)!=0:

f = File (' Account_file ')

Loginsuccess = False

For line in F.readlines ():

If username = = Line.split () [0] and Password = = Line.split () [1]: #user and passwd are correct

Print "Welcome%s login my system"% username

Break

If Loginsuccess is True: #login success

Break

Else

Continue

-------------------------------

Version-2

-------------------------------

Import OS

Account_file = ' Account.txt '

Lock_file = ' Loack.txt '


# put account in a list

F =file (Account_file)

Account_list = F.readlines ()

F.close ()


While True:

# put locked user into a lock list

f = File (Lock_file)

Lock_list = []

For I in F.readlines ():

Line=i.strip (' \ n ')

Lock_list.append (line)

F.close ()

Loginsuccess = False

Userame =raw_input (' username: '). Strip ()

If username in lock_list:

Print "Sorry,you is already in the block list,getthe fuking out!"

Break

For line in Account_list:

line = Line.split ()

If line[0] = = Username: #username correct

For I in range (3):

Password = raw_input (' passwd: '). Strip ()

if password = = line[1]: #paswd correct

Print "Welcome%s login my system!"% username

Loginsuccess = True

Break

Else

f = File (Lock_file, ' a ')

F.write ('%s\n '%username)

Print "entered 3 times of wrong passwd,going to lock%s"% username

if loginsuccess = = True:break #jump out of a for Top loop

if loginsuccess = = True:break #jump out of the while loop


Python program 1 "Login Interface"

Related Article

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.