/ Published in: Python
                    
                                        
Not very secure, but very handy ...
Use like that :
app = your_wsgi_app()
app = ControlAccess( app, "your_password")
httpserve( app ) # wsgi server
                Use like that :
app = your_wsgi_app()
app = ControlAccess( app, "your_password")
httpserve( app ) # wsgi server
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
import Cookie,hashlib
md5 = lambda x : hashlib.md5(x).hexdigest()
class ControlAccess:
def __init__(self, appReal,password):
self.appReal = appReal
self.password=password
def __call__(self, environ, start_response):
try:
password = Cookie.SimpleCookie(environ.get("HTTP_COOKIE",""))["pass"].value
except:
password = ""
if password==md5(self.password):
for i in self.appReal(environ, start_response):
yield i
else:
try:
passw=environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])).split("=")[-1]
except:
passw=""
if passw == self.password:
cookie = Cookie.SimpleCookie()
cookie["pass"] = md5(self.password)
start_response('200 OK', [('Content-type','text/html'),('Set-Cookie',cookie["pass"].OutputString())])
yield """<html><head><meta http-equiv="refresh" content="0; url=/" /></head><body>welcome</body></html>"""
else:
start_response('200 OK', [('Content-type','text/html')])
yield """<form method="post">
Password <input type='password' name="password">
<input type='submit' value="ok">
</form>"""
Comments
 Subscribe to comments
                    Subscribe to comments
                
                