blob: 3570cf43df4d8887f1bee9375734c202aad55726 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/usr/bin/python
"""
Apache Password Hash Generation Functions
by Mike Crute on July 12, 2008
for SoftGroup Interactive, Inc.
Released under the terms of the BSD license.
A collection of functions used to generate Apache-style password hashes.
Algorithm information was collected for various sources around the web
and from analysis of the APR C code.
"""
def crypt_password(passwd):
"""Generate Apache-style CRYPT password hash.
"""
from crypt import crypt
from apachelib.md5 import generate_short_salt
return crypt(passwd, generate_short_salt())
def sha_password(passwd):
"""Generate Apache-style SHA1 password hash.
"""
from hashlib import sha1
from base64 import b64encode
return "{SHA}%s" % b64encode(sha1(passwd).digest())
def md5_password(passwd):
"""Generate Apache-style MD5 password hash.
"""
from apachelib.md5 import generate_md5
return generate_md5(passwd)
|