Skip to content

Instantly share code, notes, and snippets.

View jdahlin's full-sized avatar

Johan Dahlin jdahlin

View GitHub Profile
@lordsarcastic
lordsarcastic / Implement OTP for Django application for multiple uses
Last active April 24, 2024 14:06
This is a generic implementation of OTP for Django applications. It can be extended to any framework or platform that uses OTP.
This is a robust implementation that is extensible for anything that requires the use of OTP. Want to use OTP to verify
a user? Check! Want to use OTP to validate an order? CHeck! Want to use OTP to reset a password? CHEck! Want to use
OTP to verify a device? CHECk! Want to use OTP to fight people? CHECK!
I used: Django (framework), Django Rest Framework (a plugin for REST API), PostgreSQL (database)
and email (for sending the otp). You can substitute any of these for whatever you want, like using Redis instead of Postgres.
While this solution is built to be used for Django, I have added comments to explain the process for developers using
other frameworks.
Legend:
@jdahlin
jdahlin / generate-mypy-blacklist.md
Last active May 25, 2022 12:01
Use this script to generate a mypy.ini where you can enable strict mode based on errors from a current run.

Use this script to generate a mypy.ini where you can enable strict mode based on errors from a current run.

Needs a few improvments:

  • output pyproject.toml
  • update source files by adding # type: ignore[xxx] instead of ignore_errors
@gabrielfalcao
gabrielfalcao / rsa_encryption.py
Created November 30, 2019 00:39
Using python cryptography module to generate an RSA keypair, serialize, deserialize the keys and perform encryption and decryption
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
def utf8(s: bytes):
return str(s, 'utf-8')