summaryrefslogtreecommitdiff
path: root/password.py
diff options
context:
space:
mode:
Diffstat (limited to 'password.py')
-rw-r--r--password.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/password.py b/password.py
new file mode 100644
index 0000000..3570cf4
--- /dev/null
+++ b/password.py
@@ -0,0 +1,31 @@
1#!/usr/bin/python
2"""
3Apache Password Hash Generation Functions
4by Mike Crute on July 12, 2008
5for SoftGroup Interactive, Inc.
6Released under the terms of the BSD license.
7
8A collection of functions used to generate Apache-style password hashes.
9Algorithm information was collected for various sources around the web
10and from analysis of the APR C code.
11"""
12
13def crypt_password(passwd):
14 """Generate Apache-style CRYPT password hash.
15 """
16 from crypt import crypt
17 from apachelib.md5 import generate_short_salt
18 return crypt(passwd, generate_short_salt())
19
20def sha_password(passwd):
21 """Generate Apache-style SHA1 password hash.
22 """
23 from hashlib import sha1
24 from base64 import b64encode
25 return "{SHA}%s" % b64encode(sha1(passwd).digest())
26
27def md5_password(passwd):
28 """Generate Apache-style MD5 password hash.
29 """
30 from apachelib.md5 import generate_md5
31 return generate_md5(passwd)