auth: re-orginize imports use hashlib helpers
This commit is contained in:
parent
f2c5bfb6c6
commit
2be696ca3e
2 changed files with 17 additions and 7 deletions
|
|
@ -28,7 +28,6 @@ import colander
|
|||
import time
|
||||
import collections
|
||||
import fnmatch
|
||||
import hashlib
|
||||
import itertools
|
||||
import logging
|
||||
import random
|
||||
|
|
@ -50,11 +49,14 @@ from rhodecode.model.db import (
|
|||
false, User, Repository, Permission, UserToPerm, UserGroupToPerm, UserGroupMember,
|
||||
UserIpMap, UserApiKeys, RepoGroup, UserGroup, UserNotice)
|
||||
from rhodecode.lib import rc_cache
|
||||
from rhodecode.lib.utils2 import safe_unicode, aslist, safe_str, md5, safe_int, sha1
|
||||
from rhodecode.lib.utils import (
|
||||
get_repo_slug, get_repo_group_slug, get_user_group_slug)
|
||||
from rhodecode.lib.type_utils import aslist
|
||||
from rhodecode.lib.hash_utils import sha1, sha256, md5
|
||||
from rhodecode.lib.str_utils import ascii_bytes, safe_str, safe_int, safe_bytes
|
||||
from rhodecode.lib.caching_query import FromCache
|
||||
|
||||
|
||||
if rhodecode.is_unix:
|
||||
import bcrypt
|
||||
|
||||
|
|
@ -196,7 +198,7 @@ class _RhodeCodeCryptoSha256(_RhodeCodeCryptoBase):
|
|||
|
||||
def hash_create(self, str_):
|
||||
self._assert_bytes(str_)
|
||||
return hashlib.sha256(str_).hexdigest()
|
||||
return sha256(str_)
|
||||
|
||||
def hash_check(self, password, hashed):
|
||||
"""
|
||||
|
|
@ -206,7 +208,7 @@ class _RhodeCodeCryptoSha256(_RhodeCodeCryptoBase):
|
|||
:param hashed: password in hashed form
|
||||
"""
|
||||
self._assert_bytes(password)
|
||||
return hashlib.sha256(password).hexdigest() == hashed
|
||||
return sha256(password) == hashed
|
||||
|
||||
|
||||
class _RhodeCodeCryptoTest(_RhodeCodeCryptoBase):
|
||||
|
|
@ -274,7 +276,7 @@ def generate_auth_token(data, salt=None):
|
|||
|
||||
if salt is None:
|
||||
salt = os.urandom(16)
|
||||
return hashlib.sha1(safe_str(data) + salt).hexdigest()
|
||||
return sha1(data + salt)
|
||||
|
||||
|
||||
def get_came_from(request):
|
||||
|
|
@ -1576,7 +1578,7 @@ class AuthUser(object):
|
|||
def get_cookie_store(self):
|
||||
return {
|
||||
'username': self.username,
|
||||
'password': md5(self.password or ''),
|
||||
'password': md5(safe_bytes(self.password or '')),
|
||||
'user_id': self.user_id,
|
||||
'is_authenticated': self.is_authenticated
|
||||
}
|
||||
|
|
@ -1675,7 +1677,7 @@ def get_csrf_token(session, force_new=False, save_if_missing=True):
|
|||
# from pyramid.csrf import get_csrf_token
|
||||
|
||||
if (csrf_token_key not in session and save_if_missing) or force_new:
|
||||
token = hashlib.sha1(str(random.getrandbits(128))).hexdigest()
|
||||
token = sha1(ascii_bytes(str(random.getrandbits(128))))
|
||||
session[csrf_token_key] = token
|
||||
if hasattr(session, 'save'):
|
||||
session.save()
|
||||
|
|
|
|||
|
|
@ -36,3 +36,11 @@ def sha1(s):
|
|||
|
||||
def sha1_safe(s):
|
||||
return sha1(safe_bytes(s))
|
||||
|
||||
|
||||
def sha256(s):
|
||||
return hashlib.sha256(s).hexdigest()
|
||||
|
||||
|
||||
def sha256_safe(s):
|
||||
return sha256(safe_bytes(s))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue