1
2
3
4
5
6 from hashlib import sha256
7 import os
8
9
10 from .... import Document, SchemaListProperty, StringProperty, \
11 StringListProperty
15
22
23 -class User(Document):
24 """The base User model. This should be extended by the user."""
25 login = StringProperty(required=True)
26 password = StringProperty(required=True)
27 groups = StringListProperty()
28
29 @staticmethod
31 if isinstance(cleartext, unicode):
32 password_8bit = cleartext.encode('UTF-8')
33 else:
34 password_8bit = cleartext
35
36 salt = sha256()
37 salt.update(os.urandom(60))
38 hash = sha256()
39 hash.update(password_8bit + salt.hexdigest())
40 hashed_password = salt.hexdigest() + hash.hexdigest()
41
42 if not isinstance(hashed_password, unicode):
43 hashed_password = hashed_password.decode('UTF-8')
44 return hashed_password
45
48
49 @staticmethod
51 user = User.view("user/by_login", key=login).one()
52 if not user:
53 return None
54
55 hashed_pass = sha256()
56 hashed_pass.update(password + user.password[:64])
57 if user.password[64:] != hashed_pass.hexdigest():
58 return None
59 return user
60