summaryrefslogtreecommitdiff
path: root/htpasswd.py
diff options
context:
space:
mode:
Diffstat (limited to 'htpasswd.py')
-rw-r--r--htpasswd.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/htpasswd.py b/htpasswd.py
new file mode 100644
index 0000000..3641c34
--- /dev/null
+++ b/htpasswd.py
@@ -0,0 +1,35 @@
1#!/usr/bin/python
2"""
3Apache htaccess File Library
4by Mike Crute on July 12, 2008
5for SoftGroup Interactive, Inc.
6Released under the terms of the BSD license.
7
8A collection of classes and functions to manipulate apache htaccess files.
9"""
10
11__all__ = [ "generate_user" ]
12
13def hash_password(passwd, ctype="crypt"):
14 """Create an Apache-style password hash.
15 This is basically just a simplfified interface to apachelib.password
16 for use in generating htaccess files. Valid ctypes are crypt, sha and
17 md5.
18 """
19 if ctype is "crypt":
20 from apachelib.password import crypt_password
21 return crypt_password(passwd)
22 elif ctype is "sha":
23 from apachelib.password import sha_password
24 return sha_password(passwd)
25 elif ctype is "md5":
26 from apachelib.password import md5_password
27 return md5_password(passwd)
28
29 # We should never get here
30 raise ValueError("%s is not a valid value for ctype." % ctype)
31
32def generate_user(username, passwd, ctype="crypt"):
33 """Generate a single htaccess line.
34 """
35 return "%s:%s" % (username, hash_password(passwd, ctype))