mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
29 lines
681 B
Python
29 lines
681 B
Python
"""
|
|
Functions not dependent on advlabdb.models.
|
|
"""
|
|
|
|
import secrets
|
|
from string import ascii_letters, digits
|
|
|
|
from sqlalchemy import func, select
|
|
|
|
from . import app, db
|
|
|
|
PASSWORD_CHARS: str = ascii_letters + digits + "!%*+=?"
|
|
|
|
|
|
def randomPassword() -> str:
|
|
password_length = app.config["SECURITY_PASSWORD_LENGTH_MIN"]
|
|
return "".join(secrets.choice(PASSWORD_CHARS) for i in range(password_length))
|
|
|
|
|
|
def reportBadAttempt(message: str) -> None:
|
|
print("BAD ATTEMPT:", message) # TODO: Log
|
|
|
|
|
|
def get_count(table):
|
|
return db.session.scalar(select(func.count()).select_from(table))
|
|
|
|
|
|
def get_first(table):
|
|
return db.session.execute(table.limit(1)).scalars().first()
|