##// END OF EJS Templates
auth: re-orginize imports use hashlib helpers
super-admin -
r4958:8dd2ba8f default
parent child Browse files
Show More
@@ -28,7 +28,6 b' import colander'
28 28 import time
29 29 import collections
30 30 import fnmatch
31 import hashlib
32 31 import itertools
33 32 import logging
34 33 import random
@@ -50,11 +49,14 b' from rhodecode.model.db import ('
50 49 false, User, Repository, Permission, UserToPerm, UserGroupToPerm, UserGroupMember,
51 50 UserIpMap, UserApiKeys, RepoGroup, UserGroup, UserNotice)
52 51 from rhodecode.lib import rc_cache
53 from rhodecode.lib.utils2 import safe_unicode, aslist, safe_str, md5, safe_int, sha1
54 52 from rhodecode.lib.utils import (
55 53 get_repo_slug, get_repo_group_slug, get_user_group_slug)
54 from rhodecode.lib.type_utils import aslist
55 from rhodecode.lib.hash_utils import sha1, sha256, md5
56 from rhodecode.lib.str_utils import ascii_bytes, safe_str, safe_int, safe_bytes
56 57 from rhodecode.lib.caching_query import FromCache
57 58
59
58 60 if rhodecode.is_unix:
59 61 import bcrypt
60 62
@@ -196,7 +198,7 b' class _RhodeCodeCryptoSha256(_RhodeCodeC'
196 198
197 199 def hash_create(self, str_):
198 200 self._assert_bytes(str_)
199 return hashlib.sha256(str_).hexdigest()
201 return sha256(str_)
200 202
201 203 def hash_check(self, password, hashed):
202 204 """
@@ -206,7 +208,7 b' class _RhodeCodeCryptoSha256(_RhodeCodeC'
206 208 :param hashed: password in hashed form
207 209 """
208 210 self._assert_bytes(password)
209 return hashlib.sha256(password).hexdigest() == hashed
211 return sha256(password) == hashed
210 212
211 213
212 214 class _RhodeCodeCryptoTest(_RhodeCodeCryptoBase):
@@ -274,7 +276,7 b' def generate_auth_token(data, salt=None)'
274 276
275 277 if salt is None:
276 278 salt = os.urandom(16)
277 return hashlib.sha1(safe_str(data) + salt).hexdigest()
279 return sha1(data + salt)
278 280
279 281
280 282 def get_came_from(request):
@@ -1576,7 +1578,7 b' class AuthUser(object):'
1576 1578 def get_cookie_store(self):
1577 1579 return {
1578 1580 'username': self.username,
1579 'password': md5(self.password or ''),
1581 'password': md5(safe_bytes(self.password or '')),
1580 1582 'user_id': self.user_id,
1581 1583 'is_authenticated': self.is_authenticated
1582 1584 }
@@ -1675,7 +1677,7 b' def get_csrf_token(session, force_new=Fa'
1675 1677 # from pyramid.csrf import get_csrf_token
1676 1678
1677 1679 if (csrf_token_key not in session and save_if_missing) or force_new:
1678 token = hashlib.sha1(str(random.getrandbits(128))).hexdigest()
1680 token = sha1(ascii_bytes(str(random.getrandbits(128))))
1679 1681 session[csrf_token_key] = token
1680 1682 if hasattr(session, 'save'):
1681 1683 session.save()
@@ -36,3 +36,11 b' def sha1(s):'
36 36
37 37 def sha1_safe(s):
38 38 return sha1(safe_bytes(s))
39
40
41 def sha256(s):
42 return hashlib.sha256(s).hexdigest()
43
44
45 def sha256_safe(s):
46 return sha256(safe_bytes(s))
General Comments 0
You need to be logged in to leave comments. Login now