當前位置: 首頁>>代碼示例>>Python>>正文


Python secrets.compare_digest方法代碼示例

本文整理匯總了Python中secrets.compare_digest方法的典型用法代碼示例。如果您正苦於以下問題:Python secrets.compare_digest方法的具體用法?Python secrets.compare_digest怎麽用?Python secrets.compare_digest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在secrets的用法示例。


在下文中一共展示了secrets.compare_digest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: login

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def login():
    if request.method == 'GET':
        return '''
               <form method='POST'>
                <input type='text' name='username' id='username' placeholder='username'></input>
                <input type='password' name='password' id='password' placeholder='password'></input>
                <input type='submit' name='submit'></input>
               </form>
               '''

    username = (await request.form)['username']
    password = (await request.form)['password']
    if username in users and compare_digest(password, users[username]['password']):
        user = User()
        user.id = username
        flask_login.login_user(user)
        return redirect(url_for('protected'))

    return 'Bad login' 
開發者ID:pgjones,項目名稱:quart,代碼行數:21,代碼來源:flask_ext.py

示例2: validate_token

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def validate_token(self, token, user_id=None):
		try:
			token_user_id, secret = self.decode_token(token)
		except:  # XXX
			secrets.compare_digest(token, token)
			return False

		if user_id is None:
			# allow auth with just a secret
			user_id = token_user_id

		db_secret = await self.bot.pool.fetchval(self.queries.existing_token(), user_id)
		if db_secret is None:
			secrets.compare_digest(token, token)
			return False

		db_token = self.encode_token(user_id, db_secret)
		return secrets.compare_digest(token, db_token) and user_id 
開發者ID:EmoteBot,項目名稱:EmoteCollector,代碼行數:20,代碼來源:api.py

示例3: is_mnemonic_valid

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def is_mnemonic_valid(self, mnemonic):
        words = normalize_string(mnemonic).split(" ")
        num_words = len(words)

        if num_words not in VALID_WORD_COUNTS:
            return False

        try:
            indices = tuple(self.wordlist.index(w) for w in words)
        except ValueError:
            return False

        encoded_seed = bitarray()
        for idx in indices:
            # Build bitarray from tightly packing indices (which are 11-bits integers)
            encoded_seed.extend(int2ba(idx, length=11))

        entropy_size = 4 * num_words // 3

        # Checksum the raw entropy bits
        checksum = bitarray()
        checksum.frombytes(sha256(encoded_seed[:entropy_size * 8].tobytes()))
        computed_checksum = checksum[:len(encoded_seed) - entropy_size * 8].tobytes()

        # Extract the stored checksum bits
        stored_checksum = encoded_seed[entropy_size * 8:].tobytes()

        # Check that the stored matches the relevant slice of the actual checksum
        # NOTE: Use secrets.compare_digest for protection again timing attacks
        return secrets.compare_digest(stored_checksum, computed_checksum) 
開發者ID:ethereum,項目名稱:eth-account,代碼行數:32,代碼來源:mnemonic.py

示例4: request_loader

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def request_loader(request):
    username = request.form.get('username')
    password = request.form.get('password', '')
    if username not in users:
        return

    user = User()
    user.id = username
    user.is_authenticated = compare_digest(password, users[username]['password'])
    return user 
開發者ID:pgjones,項目名稱:quart,代碼行數:12,代碼來源:flask_ext.py

示例5: get

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def get(self, request):
        token = request.args.get("token") or ""
        if not self.ds._root_token:
            raise Forbidden("Root token has already been used")
        if secrets.compare_digest(token, self.ds._root_token):
            self.ds._root_token = None
            response = Response.redirect("/")
            response.set_cookie(
                "ds_actor", self.ds.sign({"a": {"id": "root"}}, "actor")
            )
            return response
        else:
            raise Forbidden("Invalid token") 
開發者ID:simonw,項目名稱:datasette,代碼行數:15,代碼來源:special.py

示例6: get_current_username

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
    correct_username = secrets.compare_digest(credentials.username, "stanleyjobson")
    correct_password = secrets.compare_digest(credentials.password, "swordfish")
    if not (correct_username and correct_password):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Incorrect email or password",
            headers={"WWW-Authenticate": "Basic"},
        )
    return credentials.username 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:12,代碼來源:tutorial007.py

示例7: _verify_token

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def _verify_token(self, request):
        if not self.token:
            return True
        actor_token = request.headers.get('actor-token')
        if not actor_token:
            return False
        return secrets.compare_digest(actor_token, self.token) 
開發者ID:anyant,項目名稱:rssant,代碼行數:9,代碼來源:receiver.py

示例8: is_valid_signature

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def is_valid_signature(self, signature: str) -> bool:
        return compare_digest(self.get_signature(), signature) 
開發者ID:getsentry,項目名稱:zeus,代碼行數:4,代碼來源:hook.py

示例9: _compare_tokens

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def _compare_tokens(self, tokenA, tokenB):
        if tokenA is None or tokenB is None:
            return False
        return secrets.compare_digest(tokenA, tokenB) 
開發者ID:microsoft,項目名稱:aerial_wildlife_detection,代碼行數:6,代碼來源:middleware.py

示例10: is_response_packet

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def is_response_packet(self, packet: Packet) -> bool:
        return (
            isinstance(packet, WhoAreYouPacket) and
            secrets.compare_digest(packet.token, self.initiating_packet.auth_tag)
        ) 
開發者ID:ethereum,項目名稱:trinity,代碼行數:7,代碼來源:handshake.py

示例11: check_user

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def check_user(user: User, password: str) -> bool:
    hashpass, salt = user_info[user].hashed_password
    target_hash_pass = hash_password(password, salt)[0]
    sleep(random.expovariate(10))
    return secrets.compare_digest(hashpass, target_hash_pass) 
開發者ID:rhettinger,項目名稱:modernpython,代碼行數:7,代碼來源:pubsub.py

示例12: test_equal

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def test_equal(self):
        # Test compare_digest functionality with equal (byte/text) strings.
        for s in ("a", "bcd", "xyz123"):
            a = s*100
            b = s*100
            self.assertTrue(secrets.compare_digest(a, b))
            self.assertTrue(secrets.compare_digest(a.encode('utf-8'), b.encode('utf-8'))) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:9,代碼來源:test_secrets.py

示例13: test_unequal

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def test_unequal(self):
        # Test compare_digest functionality with unequal (byte/text) strings.
        self.assertFalse(secrets.compare_digest("abc", "abcd"))
        self.assertFalse(secrets.compare_digest(b"abc", b"abcd"))
        for s in ("x", "mn", "a1b2c3"):
            a = s*100 + "q"
            b = s*100 + "k"
            self.assertFalse(secrets.compare_digest(a, b))
            self.assertFalse(secrets.compare_digest(a.encode('utf-8'), b.encode('utf-8'))) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:11,代碼來源:test_secrets.py

示例14: test_bad_types

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def test_bad_types(self):
        # Test that compare_digest raises with mixed types.
        a = 'abcde'
        b = a.encode('utf-8')
        assert isinstance(a, str)
        assert isinstance(b, bytes)
        self.assertRaises(TypeError, secrets.compare_digest, a, b)
        self.assertRaises(TypeError, secrets.compare_digest, b, a) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:10,代碼來源:test_secrets.py

示例15: test_bool

# 需要導入模塊: import secrets [as 別名]
# 或者: from secrets import compare_digest [as 別名]
def test_bool(self):
        # Test that compare_digest returns a bool.
        self.assertIsInstance(secrets.compare_digest("abc", "abc"), bool)
        self.assertIsInstance(secrets.compare_digest("abc", "xyz"), bool) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:6,代碼來源:test_secrets.py


注:本文中的secrets.compare_digest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。