-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (41 loc) · 1.65 KB
/
app.py
File metadata and controls
53 lines (41 loc) · 1.65 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, request, jsonify
import hashlib
import random
import json
app = Flask(__name__)
# Şifre üretme fonksiyonu
def generate_password():
# 6 haneli sadece rakamlardan oluşan bir şifre üret
password = "".join(random.choices("0123456789", k=6)) # 6 haneye güncellendi
print(f"Oluşturulan şifre (hashlenmeden önce): {password}") # Konsola yazdır
return password
@app.route("/get_password", methods=["GET"])
def get_password():
# Şifre oluştur ve hashle
password = generate_password()
password_hash = hashlib.md5(password.encode()).hexdigest()
# Hashlenmiş şifreyi döndür ve hem hash'i hem de açık şifreyi dosyaya yaz
with open("password.json", "w") as f:
json.dump({"password": password, "hash": password_hash}, f, indent=4) # Şifre ve hash yazılıyor
# JSON yanıt olarak sadece hash döndürülüyor
return jsonify({"password": password_hash})
@app.route("/check_password", methods=["POST"])
def check_password():
# Gelen veriden şifreyi al
data = request.get_json()
password = data.get("password")
password_hash = hashlib.md5(password.encode()).hexdigest()
# Kaydedilen hash'i dosyadan oku
try:
with open("password.json", "r") as f:
stored_data = json.load(f)
stored_hash = stored_data.get("hash")
except FileNotFoundError:
return jsonify({"message": "Error", "detail": "Password file not found"}), 500
# Hash doğrulaması yap
if password_hash == stored_hash:
return jsonify({"message": "Success"})
else:
return jsonify({"message": "Failed"})
if __name__ == "__main__":
app.run()