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)
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)
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))
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
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
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)
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')
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
def match(self, encoded): """True if encoded appears to match this scheme.""" encoded = check_unicode(encoded) return encoded.startswith(self.PREFIX)