blob: cbdf4fddf95573d9e20bf17654ab0e7945322b60 (
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#!/usr/bin/python
import base64
import os
import sys
# Workaround current bug in docutils:
# http://permalink.gmane.org/gmane.text.docutils.devel/6324
import docutils.utils
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(root)
import config
import store
import passlib.registry
bcrypt = passlib.registry.get_crypt_handler("bcrypt")
bcrypt_sha1 = passlib.registry.get_crypt_handler("bcrypt_sha1")
cfg = config.Config(os.path.join(root, "config.ini"))
st = store.Store(cfg)
print "Migrating passwords to bcrypt_sha1 from unsalted sha1....",
st.open()
for i, u in enumerate(st.get_users()):
user = st.get_user(u['name'])
# basic sanity check to allow it to run concurrent with users accessing
if len(user['password']) == 40 and "$" not in user["password"]:
# Hash the existing sha1 password with bcrypt
bcrypted = bcrypt.encrypt(user["password"])
# Base64 encode the bcrypted password so that it's just a blob of data
encoded = base64.b64encode(bcrypted)
st.setpasswd(user['name'], bcrypt_sha1._hash_prefix + encoded,
hashed=True,
)
# Commit every 20 users
if not i % 20:
st.commit()
st.open()
st.commit()
st.close()
print "[ok]"
|