-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth_hashing.py
More file actions
29 lines (20 loc) · 872 Bytes
/
Copy pathauth_hashing.py
File metadata and controls
29 lines (20 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# CWE-327: Use of a Broken or Risky Cryptographic Algorithm
# Vulnerable: MD5 used for password hashing, no salt, no slow hash function.
import hashlib
from flask import Flask, request
app = Flask(__name__)
def hash_password(password: str) -> str:
# VULNERABLE: MD5 is fast and broken, unsuitable for password storage
return hashlib.md5(password.encode()).hexdigest()
def verify_password(password: str, stored_hash: str) -> bool:
return hash_password(password) == stored_hash
@app.route("/register", methods=["POST"])
def register():
username = request.form.get("username")
password = request.form.get("password")
# VULNERABLE: same weak hash reused for storage
hashed = hash_password(password)
# ... store username, hashed in DB
return {"username": username, "hash": hashed}
if __name__ == "__main__":
app.run(debug=True)