Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add htpasswd authentication module

  • Loading branch information...
commit 9492304920a4d939b3b30e69d283cd7949731cd4 1 parent 33f6190
Steven Kryskalla authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 barrel/htpasswd.py
26 barrel/htpasswd.py
View
@@ -0,0 +1,26 @@
+"""htpasswd - htpasswd compatible authentication module.
+
+Pass in the path to an htpasswd file, and basic auth will validate users
+and passwords from that file.
+
+Copyright (C) 2012 Steven Kryskalla - http://lost-theory.org/
+
+See README for license info.
+"""
+
+from barrel.basic import BasicAuth
+
+from crypt import crypt
+
+class HtpasswdBasicAuth(BasicAuth):
+ def __init__(self, app, htpasswd_path):
+ self.app = app
+ htpasswd = open(htpasswd_path)
+ htpasswd = [line.strip().split(':') for line in htpasswd]
+ self.htpasswd = dict(htpasswd)
+
+ def valid_user(self, username, password):
+ if username not in self.htpasswd:
+ return False
+ vhash = self.htpasswd[username]
+ return crypt(password, vhash) == vhash
Please sign in to comment.
Something went wrong with that request. Please try again.