This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseJwt (token) { | |
| // https://stackoverflow.com/questions/38552003/how-to-decode-jwt-token-in-javascript | |
| var base64Url = token.split('.')[1]; | |
| var base64 = decodeURIComponent(atob(base64Url).split('').map((c)=>{ | |
| return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | |
| }).join('')); | |
| return JSON.parse(base64); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import the Python Library | |
| import sys | |
| import bcrypt | |
| #!{sys.executable} -m pip install bcrypt | |
| password = b"studyhard" | |
| # Hash a password for the first time, with a certain number of rounds | |
| salt = bcrypt.gensalt(14) | |
| hashed = bcrypt.hashpw(password, salt) | |
| print(salt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import Package | |
| from cryptography.fernet import Fernet | |
| # Generate a Key and Instantiate a Fernet Instance | |
| key = Fernet.generate_key() | |
| f = Fernet(key) | |
| print(key) | |
| # Define our message | |
| plaintext = b"encryption is very useful" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Install a pip package in the current Jupyter kernel | |
| import sys | |
| !{sys.executable} -m pip install python-jose | |
| import json | |
| from jose import jwt | |
| from urllib.request import urlopen | |
| # Configuration | |
| # UPDATE THIS TO REFLECT YOUR AUTH0 ACCOUNT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import Python Package | |
| import jwt | |
| import base64 | |
| # Init our Data | |
| payload = {'hamdy':'software engineer'} | |
| algo = 'HS256' #HMAC-SHA 256 | |
| secret = 'learning' | |
| # Encode a JWT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| # Our Basic Function Defn | |
| def print_name(name): | |
| print(name) | |
| print_name("jimmy") | |
| # Let's add a simple decorator to inject a greeting | |
| def add_greeting(f): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Init the engine | |
| import os | |
| from sqlalchemy import create_engine, Column, String, Integer | |
| database_filename = "test.db" | |
| project_dir = os.path.dirname(os.path.abspath('')) | |
| database_path = "sqlite:///{}".format(os.path.join(project_dir, database_filename)) | |
| engine = create_engine(database_path) |