1 #!/usr/bin/env python2 #Coding:utf-83 4Name="Alex"5psw="abc123"6 7 defAuth (func):8 defWrapper (*args,**Kwargs):9Username=input ('input your username:')TenPassword=input ('Input your password:') One A ifUsername==name andpassword==PSW: - returnFunc (*args,**Kwargs) - Else: the Print('inalid username and password!') - returnwrapper - - + @auth - defHome (): + Print('Home') A return 'home!!' at @auth - defadmin (): - Print('Admin') - @auth - defBBS (): - Print('BBS') in - Home () to admin () +BBS ()
Add multiple types of validation
1 #!/usr/bin/env python2 #Coding:utf-83 4Name="Alex"5psw="abc123"6 7 defAuth (auth_type):8 Print('---------', Auth_type)9 defOut_wrapper (func):Ten Print('---------', func) One defWrapper (*args,**Kwargs): AUsername=input ('input your username:') -Password=input ('Input your password:') - the ifUsername==name andpassword==PSW: - returnFunc (*args,**Kwargs) - Else: - Print('inalid username and password!') + returnwrapper - returnOut_wrapper + A #added login multiple authentication at@auth (auth_type='file') - defHome (): - Print('Home') -@auth (auth_type='localhost') - defadmin (): - Print('Admin') in@auth (auth_type='LDAP') - defBBS (): to Print('BBS') + - Home () the admin () *BBS ()
Python Learning: Adorner usage