MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / login

Function login

Scripts/ButSystem.py:10600–10660  ·  view source on GitHub ↗

login. Route handler or application helper. This docstring was expanded to make future maintenance easier. Returns: Varies.

()

Source from the content-addressed store, hash-verified

10598 return "Password is too easy to guess."
10599 return None
10600
10601def _host_is_allowed(hostname: str) -> bool:
10602 host = (hostname or "").strip().lower()
10603 if not host:
10604 return False
10605 if host in {"localhost", "127.0.0.1", "::1"}:
10606 return True
10607 if host.endswith(".trycloudflare.com") or host.endswith(".onion"):
10608 return True
10609 try:
10610 ip_obj = ipaddress.ip_address(host)
10611 return bool(ip_obj.is_private or ip_obj.is_loopback or ip_obj.is_link_local)
10612 except Exception:
10613 pass
10614 # Allow normal domain names used by reverse proxies / custom domains.
10615 if re.fullmatch(r"[a-z0-9.-]{1,253}", host) and "." in host:
10616 return True
10617 return False
10618
10619# ---------------------------
10620# Public-link QR generation
10621# ---------------------------
10622
10623CURRENT_LOCAL_URL = None
10624CURRENT_LOCALHOST_URL = None
10625
10626
10627def _qr_placeholder_data_uri() -> str:
10628 """Return a non-crashing placeholder if the qrcode package is unavailable."""
10629 svg = (
10630 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240">'
10631 '<rect width="240" height="240" fill="white"/>'
10632 '<rect x="16" y="16" width="208" height="208" rx="16" fill="none" stroke="#111" stroke-width="6"/>'
10633 '<text x="120" y="112" text-anchor="middle" font-family="sans-serif" font-size="18" fill="#111">QR unavailable</text>'
10634 '<text x="120" y="140" text-anchor="middle" font-family="sans-serif" font-size="13" fill="#444">Use the text link below</text>'
10635 '</svg>'
10636 )
10637 return "data:image/svg+xml;base64," + base64.b64encode(svg.encode("utf-8")).decode("ascii")
10638
10639
10640def _link_barcode_data_uri(link: str) -> str:
10641 """Generate a fresh SVG QR image for one URL without writing temporary files."""
10642 value = str(link or "").strip()
10643 if not value:
10644 return _qr_placeholder_data_uri()
10645 try:
10646 if qrcode is None:
10647 raise RuntimeError("Python package 'qrcode' is unavailable")
10648 qr = qrcode.QRCode(
10649 version=None,
10650 error_correction=qrcode.constants.ERROR_CORRECT_M,
10651 box_size=8,
10652 border=3,
10653 )
10654 qr.add_data(value)
10655 qr.make(fit=True)
10656 image = qr.make_image(image_factory=qrcode.image.svg.SvgPathImage)
10657 output = io.BytesIO()

Callers

nothing calls this directly

Calls 11

_client_ipFunction · 0.70
_too_many_attemptsFunction · 0.70
_Function · 0.70
_rate_limit_hitFunction · 0.70
db_connectFunction · 0.70
_mark_failFunction · 0.70
current_scopeFunction · 0.70
scope_capacity_okFunction · 0.70
user_2fa_enabledFunction · 0.70
_clear_failFunction · 0.70
_complete_login_sessionFunction · 0.70

Tested by

no test coverage detected