import win32security from typing import Optional from fastapi import Body, FastAPI from pydantic import BaseModel, Field from uvicorn import run app = FastAPI() def login_windows_func(user_name:str,password:str): try: token = win32security.LogonUser( user_name, 'ZAMAZINGODOM', password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT) authenticated = bool(token) return authenticated except Exception as e: print (str(e)) return False class LoginForm(BaseModel): username: str password: str @app.post("/login") async def login_windows(request:LoginForm): user_name = request.username passw = request.password if login_windows_func(user_name,passw): return {'success':True} else: return {'success':False} if __name__ == '__main__': run(app, host='0.0.0.0', port=8563)