cloud_off
You are offline. Reconnect to keep browsing.
data_object
Snippet library
Copy-ready, tested snippets for Python, Flask, JavaScript, SQL, HTML, CSS and Bash. Open any of them in the playground.
3 snippets
python
Use the secrets module (never random) for passwords, tokens and reset links.
import secrets
import string
reset_token = secrets.token_urlsafe(32) # for links: /reset/<token>
api_key = "pk_" + secrets.token_hex(24)
beginner
#security#secrets#auth
flask
Answer 401 JSON instead of redirecting to the login page.
from functools import wraps
from flask import jsonify
from flask_login import current_user
intermediate
#auth#decorators#api
flask
Make email-verification or reset links that expire, without a database table.
from itsdangerous import URLSafeTimedSerializer, BadSignature, SignatureExpired
serializer = URLSafeTimedSerializer(app.config["SECRET_KEY"], salt="email-verify")
intermediate
#auth#email#tokens
bookmark_borderNo saved snippets on this page yet. Use the bookmark button to save one.