-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpassword.py
More file actions
25 lines (20 loc) · 740 Bytes
/
password.py
File metadata and controls
25 lines (20 loc) · 740 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
# Copyright (c) 2022 - Itz-fork
from random import sample
from fastapi import APIRouter
from string import punctuation
from secrets import token_urlsafe
from ..functions.response import send_response
from ..models.Tools import PasswordModel
from ..config.basic import NX_Basic
route = APIRouter()
@route.get(
"/password",
description="Generates a random password according to the given length",
response_model=PasswordModel,
tags=["Tools"])
async def password_generator(length: int = 12):
if length > NX_Basic["pass_limit"]:
return await send_response(500, [])
tkn = token_urlsafe(length)
punc = "".join(sample(punctuation, 1))
return await send_response("".join(sample(f"{tkn+punc}", length)))