comparison MoinMoin/support/md5crypt.py @ 5731:8692137f2ccc

md5crypt: fix python 2.4 compatibility, untested
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 26 Nov 2010 21:21:16 +0100
parents 69668ad0cae7
children
comparison
equal deleted inserted replaced
5730:d70b5147ef0b 5731:8692137f2ccc
39 """ 39 """
40 40
41 MAGIC = '$1$' # Magic string 41 MAGIC = '$1$' # Magic string
42 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 42 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
43 43
44 import hashlib 44 try:
45 import hashlib
46 hash_md5 = hashlib.md5
47 except ImportError:
48 # maybe we have python < 2.5 (no hashlib)
49 import md5
50 hash_md5 = md5.new
51
45 52
46 def to64 (v, n): 53 def to64 (v, n):
47 ret = '' 54 ret = ''
48 while (n - 1 >= 0): 55 while (n - 1 >= 0):
49 n = n - 1 56 n = n - 1
72 salt = string.split(salt, '$', 1)[0] 79 salt = string.split(salt, '$', 1)[0]
73 salt = salt[:8] 80 salt = salt[:8]
74 81
75 ctx = pw + magic + salt 82 ctx = pw + magic + salt
76 83
77 md5 = hashlib.md5() 84 md5 = hash_md5()
78 md5.update(pw + salt + pw) 85 md5.update(pw + salt + pw)
79 final = md5.digest() 86 final = md5.digest()
80 87
81 for pl in range(len(pw),0,-16): 88 for pl in range(len(pw),0,-16):
82 if pl > 16: 89 if pl > 16:
93 ctx = ctx + chr(0) #if ($i & 1) { $ctx->add(pack("C", 0)); } 100 ctx = ctx + chr(0) #if ($i & 1) { $ctx->add(pack("C", 0)); }
94 else: 101 else:
95 ctx = ctx + pw[0] 102 ctx = ctx + pw[0]
96 i = i >> 1 103 i = i >> 1
97 104
98 md5 = hashlib.md5() 105 md5 = hash_md5()
99 md5.update(ctx) 106 md5.update(ctx)
100 final = md5.digest() 107 final = md5.digest()
101 108
102 # The following is supposed to make 109 # The following is supposed to make
103 # things run slower. 110 # things run slower.
121 ctx1 = ctx1 + final[:16] 128 ctx1 = ctx1 + final[:16]
122 else: 129 else:
123 ctx1 = ctx1 + pw 130 ctx1 = ctx1 + pw
124 131
125 132
126 md5 = hashlib.md5() 133 md5 = hash_md5()
127 md5.update(ctx1) 134 md5.update(ctx1)
128 final = md5.digest() 135 final = md5.digest()
129 136
130 137
131 # Final xform 138 # Final xform