added login cookie, added change pwd screen

This commit is contained in:
2026-01-18 08:22:41 +01:00
parent 2d7297e3b7
commit 23631c6d24
10 changed files with 480 additions and 22 deletions
+59
View File
@@ -0,0 +1,59 @@
import pickle
from cryptography.fernet import Fernet
# =====================================================
# SECRET KEY (only your program has this)
# =====================================================
# Generate once using: Fernet.generate_key()
_SECRET_KEY = b'YFK7QCyTzhyLO4vqrnRxvDAI5uu8mXEYrInEjbRoQgs='
fernet = Fernet(_SECRET_KEY)
# =====================================================
# ENCRYPT
# =====================================================
def encrypt_object(obj) -> bytes:
"""
Encrypt any Python object and return encrypted bytes.
"""
serialized = pickle.dumps(obj)
encrypted = fernet.encrypt(serialized)
return encrypted
# =====================================================
# DECRYPT
# =====================================================
def decrypt_object(encrypted_data: bytes):
"""
Decrypt bytes back into the original Python object.
"""
decrypted = fernet.decrypt(encrypted_data)
obj = pickle.loads(decrypted)
return obj
# =====================================================
# EXAMPLE USAGE
# =====================================================
if __name__ == "__main__":
original_object = {
"user": "alice",
"permissions": ["read", "write"],
"balance": 123.45
}
encrypted = encrypt_object(original_object)
print("Encrypted:", str(encrypted))
decrypted = decrypt_object(encrypted)
print("Decrypted:", decrypted)
bytes_data = b'I am a bytes string'
string_data = bytes_data.decode('utf-8')
print("Type Before :- ",type(bytes_data))
print(string_data)
print("Type After :- ",type(string_data))