diff options
Diffstat (limited to 'password.py')
-rw-r--r-- | password.py | 31 |
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 | """ | ||
3 | Apache Password Hash Generation Functions | ||
4 | by Mike Crute on July 12, 2008 | ||
5 | for SoftGroup Interactive, Inc. | ||
6 | Released under the terms of the BSD license. | ||
7 | |||
8 | A collection of functions used to generate Apache-style password hashes. | ||
9 | Algorithm information was collected for various sources around the web | ||
10 | and from analysis of the APR C code. | ||
11 | """ | ||
12 | |||
13 | def 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 | |||
20 | def 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 | |||
27 | def md5_password(passwd): | ||
28 | """Generate Apache-style MD5 password hash. | ||
29 | """ | ||
30 | from apachelib.md5 import generate_md5 | ||
31 | return generate_md5(passwd) | ||