Skip to navigation Skip to content
Simon Technology Blog
  • Architecture
  • Cloud
  • Database
  • Develop
  • Hardware
  • Industry
  • Language
  • Mobile
  • Opensource
  • OS
  • Web
Main Navigation

Use decorator to log in to verify

October 15, 2021By Simo Centos
user_list=[

{
'name':'tom','passwd':'123< span style="color: #800000;">'},
{
'name':'ubuntu','passwd':'123< span style="color: #800000;">'},
{
'name':'centos','passwd':'123< span style="color: #800000;">'},
{
'name':'jane','passwd':'123< span style="color: #800000;">'},
]
current_dict
= {'username':None,'login< span style="color: #800000;">':False}
def auth(auth_type = 'filedb'): #< span style="color: #008000;">The default verification method is filedb
def auth_func(func):
def wrapper(*args,**kwargs):
print("The authentication method is:{}".format(auth_type))
if auth_type == 'filedb':
if current_dict['username'] and current_dict['login'< span style="color: #000000;">]:
res = func()
return res
username
= input("username:>>> ").strip()
passwd
= input("passwd:>>> ").strip()
for user_dict in user_list:
if username == user_dict['name'] and passwd == user_dict['passwd ']:
current_dict[
'username'] = username
current_dict[
'login'] =True
res
= func()
return res
else:
print("Incorrect username or password")
else:
print("The ghost knows what the authentication method is--->{}" .format(auth_type))
return wrapper
return auth_func

@auth(auth_type
= 'filedb')
def index():
print("Welcome to the JD homepage")
@auth()
def home():
print("Welcome home!")

@auth(
'sssssss')
def shopping_car():
print("There is..." )

if __name__ == '__main__':
index()
home()
shopping_car()

user_list=[

{
'name':'tom','passwd':'123< span style="color: #800000;">'},
{
'name':'ubuntu','passwd':'123< span style="color: #800000;">'},
{
'name':'centos','passwd':'123< span style="color: #800000;">'},
{
'name':'jane','passwd':'123< span style="color: #800000;">'},
]
current_dict
= {'username':None,'login< span style="color: #800000;">':False}
def auth(auth_type = 'filedb'): #< span style="color: #008000;">The default verification method is filedb
def auth_func(func):
def wrapper(*args,**kwargs):
print("The authentication method is:{}".format(auth_type))
if auth_type == 'filedb':
if current_dict['username'] and current_dict['login'< span style="color: #000000;">]:
res = func()
return res
username
= input("username:>>> ").strip()
passwd
= input("passwd:>>> ").strip()
for user_dict in user_list:
if username == user_dict['name'] and passwd == user_dict['passwd ']:
current_dict[
'username'] = username
current_dict[
'login'] =True
res
= func()
return res
else:
print("Incorrect username or password")
else:
print("The ghost knows what the authentication method is--->{}" .format(auth_type))
return wrapper
return auth_func

@auth(auth_type
= 'filedb')
def index():
print("Welcome to the JD homepage")
@auth()
def home():
print("Welcome home!")

@auth(
'sssssss')
def shopping_car():
print("There is..." )

if __name__ == '__main__':
index()
home()
shopping_car()

decoration, login, Machine, procedure, verification

Post navigation

POJ 2528 Mayor’s Posters [Sub-segment tree – interval update + Discrete] [Data Structure]
PXE deploying CentOS7.6

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4912 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment Cancel reply

Your email address will not be published.

Recent Posts
  • Sencha-Touch-2 – Sencha Touch 2, Nested XML Analysis NodeValue
  • Add a separation line and format XML content
  • Is there a norm of simplified XML subsets?
  • Look at it when you write React
  • ReactJS – Present React Redux React-Router App to add the server to the Firebase hosted by the Firebase
Categories
  • Android
  • Apache
  • Apache Kafka
  • Asp
  • Auto-Test
  • Automated Build
  • Aws
  • Bitcoin
  • Browser
  • C & C++
  • C#
  • Centos
  • Cgi
  • Character
  • Cloud Service
  • Cocos2dx
  • Cordova
  • CSS
  • Data Structure
  • Delphi
  • Design Pattern
  • Dojo
  • Dubbo
  • ELK
  • Flex
  • football
  • Game
  • Hadoop
  • Hibernate
  • HTML
  • Hybrid
  • Intel
  • IOS
  • Ipad
  • iPhone
  • Java
  • Javascript
  • Jetty
  • JQuery
  • Jsp
  • Linux
  • Load Balance
  • Lua
  • Macbook
  • Macos
  • Mathematics
  • Micro Services
  • Monitoring
  • Motherboard
  • Mysql
  • Network Hardware
  • Network Marketing
  • Nginx
  • NodeJs
  • Nosql
  • Oracle
  • Os Theory
  • Performance
  • PHP
  • Postgresql
  • Power Designer
  • React
  • Redis
  • Regexp
  • Rom
  • Rss
  • Ruby
  • Search Engines
  • Shell Script
  • Silicon Valley
  • Silverlight
  • Software Design
  • Spring
  • Sql
  • Sqlite
  • Sqlserver
  • Storage
  • Storm
  • Surface
  • SVN
  • Swift
  • System Architecture
  • Tablet
  • Uncategorized
  • Unix
  • Visual Basic
  • Visual Studio
  • Web Crawler
  • WebService
  • Windows
  • Wireless
  • XML
  • ZooKeeper
Archives
  • October 2021
  • September 2021
  • August 2021
  • May 2021
  • April 2021
  • September 2020
  • September 2019
  • August 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
© Simon Technology Blog 2025 • ThemeCountry Powered by WordPress