コード例 #1
0
 def check(self, encoded, password):
     """Check a bcrypt password hash against a password."""
     password = check_unicode(password)
     encoded = check_unicode(encoded)
     if not self.match(encoded):
         return False
     rc = self._crypt(password, encoded)
     return cryptacular.core._cmp(rc, encoded)
コード例 #2
0
ファイル: __init__.py プロジェクト: scott91e1/cryptacular
 def check(self, encoded, password):
     """Check a bcrypt password hash against a password."""
     password = check_unicode(password)
     encoded = check_unicode(encoded)
     if not self.match(encoded):
         return False
     rc = self._crypt(password, encoded)
     return cryptacular.core._cmp(rc, encoded)
コード例 #3
0
ファイル: __init__.py プロジェクト: dholth/cryptacular
 def check(self, encoded, password):
     """Check a bcrypt password hash against a password."""
     password = check_unicode(password)
     encoded = check_unicode(encoded)
     if not self.match(encoded):
         return False
     rc = self._crypt(password, encoded)
     if rc == None:  # only if the stored password is not compatible with crypt()
         return False
     return cryptacular.core._cmp(rc, encoded)
コード例 #4
0
    def check(self, encoded, text):
        '''Check a bcrypt password hash against a password.
        '''
        if not self.match(encoded):
            return False

        encoded_text = self.crypt_rn(check_unicode(text), encoded)
        if encoded_text is None:
            raise ValueError('_bcrypt.crypt_rn returned None')

        return _cmp(encoded_text, check_unicode(encoded))
コード例 #5
0
    def check(self, encoded, text):
        '''Check a bcrypt password hash against a password.
        '''
        if not self.match(encoded):
            return False

        encoded_text = self.crypt_rn(check_unicode(text), encoded)
        if encoded_text is None:
            raise ValueError('_bcrypt.crypt_rn returned None')

        return _cmp(encoded_text, check_unicode(encoded))
コード例 #6
0
ファイル: __init__.py プロジェクト: dholth/cryptacular
 def encode(self, password):
     """Hash a password using the builtin crypt module."""
     salt = self.PREFIX
     salt += base64.b64encode(os.urandom(12), altchars=b"./").decode("utf-8")
     password = check_unicode(password)
     rc = self._crypt(password, salt)
     return rc
コード例 #7
0
 def encode(self, password):
     """Hash a password using the builtin crypt module."""
     salt = self.PREFIX
     salt += base64.b64encode(os.urandom(12), altchars=b'./').decode('utf-8')
     password = check_unicode(password)
     rc = self._crypt(password, salt)
     return rc
コード例 #8
0
 def check(self, encoded, password):
     encoded = check_unicode(encoded)
     if not self.match(encoded):
         return False
     iter, salt, key = encoded[len(self.PREFIX):].split('$')
     iter = int(iter, 16)
     salt = urlsafe_b64decode(salt.encode('utf-8'))
     keylen = len(urlsafe_b64decode(key.encode('utf-8')))
     hash = self.encode(password, salt, iter, keylen)
     return cryptacular.core._cmp(hash, encoded)
コード例 #9
0
 def check(self, encoded, password):
     encoded = check_unicode(encoded)
     if not self.match(encoded):
         return False
     iter, salt, key = encoded[len(self.PREFIX):].split('$')
     iter = int(iter, 16)
     salt = urlsafe_b64decode(salt.encode('utf-8'))
     keylen = len(urlsafe_b64decode(key.encode('utf-8')))
     hash = self.encode(password, salt, iter, keylen)
     return cryptacular.core._cmp(hash, encoded)
コード例 #10
0
 def encode(self, password, salt=None, rounds=None, keylen=20):
     if salt is None:
         salt = os.urandom(16)
     rounds = rounds or self.ROUNDS
     password = check_unicode(password)
     key = _pbkdf2(password, salt, rounds, keylen)
     hash =  self.PREFIX.encode('iso8859-1') + \
             ('%x' % rounds).encode('iso8859-1') + b'$' + \
             urlsafe_b64encode(salt) + b'$' + \
             urlsafe_b64encode(key)
     return hash.decode('utf-8')
コード例 #11
0
 def encode(self, password, salt=None, rounds=None, keylen=20):
     if salt is None:
         salt = os.urandom(16)
     rounds = rounds or self.ROUNDS
     password = check_unicode(password)
     key = _pbkdf2(password, salt, rounds, keylen)
     hash =  self.PREFIX.encode('iso8859-1') + \
             ('%x' % rounds).encode('iso8859-1') + b'$' + \
             urlsafe_b64encode(salt) + b'$' + \
             urlsafe_b64encode(key)
     return hash.decode('utf-8')
コード例 #12
0
    def encode(self, text, rounds=None):
        '''Hash a password using bcrypt.

        Note: only the first 72 characters of password are significant.
        '''
        rounds = rounds or self._rounds
        settings = self.crypt_gensalt_rn(self.PREFIX, rounds, os.urandom(16))
        if settings is None:
            raise ValueError('_bcrypt.crypt_gensalt_rn returned None')

        encoded = self.crypt_rn(check_unicode(text), settings)
        if encoded is None:
            raise ValueError('_bcrypt.crypt_rn returned None')

        return encoded
コード例 #13
0
    def encode(self, text, rounds=None):
        '''Hash a password using bcrypt.

        Note: only the first 72 characters of password are significant.
        '''
        rounds = rounds or self._rounds
        settings = self.crypt_gensalt_rn(self.PREFIX, rounds, os.urandom(16))
        if settings is None:
            raise ValueError('_bcrypt.crypt_gensalt_rn returned None')

        encoded = self.crypt_rn(check_unicode(text), settings)
        if encoded is None:
            raise ValueError('_bcrypt.crypt_rn returned None')

        return encoded
コード例 #14
0
 def match(self, encoded):
     """True if encoded appears to match this scheme."""
     encoded = check_unicode(encoded)
     return encoded.startswith(self.PREFIX)
コード例 #15
0
 def match(self, encoded):
     """True if encoded appears to match this scheme."""
     encoded = check_unicode(encoded)
     return encoded.startswith(self.PREFIX)