File size: 977 Bytes
a76636c
66ef082
a76636c
 
6f3b0f5
 
 
a76636c
 
 
 
 
 
 
 
 
 
 
 
6f3b0f5
 
 
a76636c
09f6c98
6f3b0f5
a76636c
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
from fastapi import APIRouter, Depends, HTTPException
from config_provider import get_config, ServiceConfig
from pydantic import BaseModel
import hashlib

router = APIRouter()

class LoginRequest(BaseModel):
    username: str
    password: str

def verify_password(stored_hash, input_password):
    # Basit SHA256 hash kontrolü (salt + hash mekanizması uygulanabilir)
    input_hash = hashlib.sha256(input_password.encode()).hexdigest()
    return stored_hash == input_hash

@router.post("/auth/login")
def login(request: LoginRequest, config: ServiceConfig = Depends(get_config)):
    user = next((u for u in config.data.get('users', []) if u['username'] == request.username), None)
    if not user:
        raise HTTPException(status_code=401, detail="Invalid username or password")

    if not verify_password(user['password_hash'], request.password):
        raise HTTPException(status_code=401, detail="Invalid username or password")

    return { "status": "success" }