|
|
| Version 2.4.0 | 12 04 08 | Français |
|
1. Introduction
2. Installing Karrigell 3. The Web server 4. Configuration options 5. Working with Apache, LightTPD or Xitami 6. Programming 7. Debugging 8. Python scripts 9. CGI scripts 10. Karrigell Services 11. Python Inside HTML 12. HTML Inside Python 13. HTMLTags - generate HTML in Python 14. Including documents 15. Sessions 16. Authentication and users management 16.1 Login(), Logout() and Role() 16.2 Example 16.3 Basic HTTP authentication 17. Translation and Unicode 18. Summary of built-in names |
16. Authentication and user management16.1 Login(), Logout() and Role()For user authentication, Karrigell provides a framework using 3 built-in functions,Login(), Logout() and Role(). The default
implementation relies on a users database managed by the script
users.ks, which is reserved to the site administrator. This script
is available from the home page : Administration/Users management
Users can have different roles, returned by function Role() :
The user management script allows you to create other roles (link "Manage user roles") ;
you can add other roles and remove default roles, except To restrict the access to a script to users who have a given role, use the function
Another script than the default
16.2 ExampleThis is the scriptloginTest.ks in webapps/demo:
def index():
# check if user is the administrator
Login(role=["edit","admin"])
# only shows is Login successful
print "Logged in as ",Role()
print "<br>",Logout()
If user is not logged is as administrator or editor, If he is logged as "edit" or "admin", If the user clicks on this link, after the logout script is run, a redirection is performed to the script. Since user is no more logged in, the 16.3 Basic HTTP authenticationKarrigell supports basic HTTP authentication, a way to protect access to some files by requesting
a user identifier and a password. The server receives user input and stores it in the global
variables In Karrigell, authentication is handled through the Here is an example with a very simple test function :
With this test function, if a visitor finds a way to read the source code, he will easily
discover a valid login/password couple. A better solution is to use md5 : it is a function which
takes a string as argument, and returns a 16-bytes "digest". The digest is guaranteed to be
different for two different strings, and it is impossible to find the string if you only know the
digest
See the
|