Python3.0 simulates user logon, three error locks, and python3.0 User Logon
# -*- coding:utf-8 -*-
# Simulate user logon as required. login is not allowed due to more than three error locks
count
=
0
#realname passwd
Real_Username
=
"test"
Real_Password
=
"test"
# Read contents from the blacklist
f
=
open
(
'black_user'
,
'r'
)
lock_file
=
f.read()
f.close()
Username
=
input
(
'Enter the User name :'
)
# Determine whether the user is in the blacklist. If the user is in the blacklist, the password cannot be entered.
for
i
in
range
(
1
):
if
lock_file
=
=
Username:
print
(
'Sorry, your user is locked and cannot be used now! '
)
exit()
else
:
continue
# Try to enter the password and count the number of inputs
for
i
in
range
(
3
):
Password
=
input
(
"Enter the password :"
)
if
Username
=
=
Real_Username
and
Password
=
=
Real_Password:
print
(
"Logon successful"
)
break
else
:
print
(
"Logon Failed"
)
count
+
=
1
# If three wrong passwords are entered, the system prompts that the user name is locked and the user name is blacklisted.
if
count
=
=
3
:
print
(
"Sorry, the number of wrong passwords you entered has reached 3, and your user name will be locked"
)
f
=
open
(
"black_user"
,
"w"
)
f.write(
"%s"
%
Username)
f.close()