122 Zeilen
3.8 KiB
Python
122 Zeilen
3.8 KiB
Python
"""
|
|
Gmail Utils - Utility-Funktionen für Gmail
|
|
"""
|
|
|
|
import logging
|
|
import random
|
|
import string
|
|
from typing import Optional
|
|
|
|
logger = logging.getLogger("gmail_utils")
|
|
|
|
class GmailUtils:
|
|
"""
|
|
Utility-Funktionen für Gmail/Google Accounts
|
|
"""
|
|
|
|
@staticmethod
|
|
def generate_gmail_username(first_name: str, last_name: str) -> str:
|
|
"""
|
|
Generiert einen Gmail-kompatiblen Benutzernamen
|
|
"""
|
|
# Basis aus Vor- und Nachname
|
|
first_clean = ''.join(c.lower() for c in first_name if c.isalnum())
|
|
last_clean = ''.join(c.lower() for c in last_name if c.isalnum())
|
|
|
|
# Verschiedene Varianten
|
|
variants = [
|
|
f"{first_clean}{last_clean}",
|
|
f"{first_clean}.{last_clean}",
|
|
f"{last_clean}{first_clean}",
|
|
f"{first_clean[0]}{last_clean}",
|
|
f"{first_clean}{last_clean[0]}"
|
|
]
|
|
|
|
# Wähle eine zufällige Variante
|
|
base = random.choice(variants)
|
|
|
|
# Füge zufällige Zahlen hinzu
|
|
random_suffix = ''.join(random.choices(string.digits, k=random.randint(2, 4)))
|
|
|
|
return f"{base}{random_suffix}"
|
|
|
|
@staticmethod
|
|
def generate_secure_password(length: int = 16) -> str:
|
|
"""
|
|
Generiert ein sicheres Passwort für Google-Anforderungen
|
|
- Mindestens 8 Zeichen
|
|
- Mischung aus Buchstaben, Zahlen und Symbolen
|
|
"""
|
|
# Stelle sicher dass alle Zeichentypen enthalten sind
|
|
password_chars = []
|
|
|
|
# Mindestens 2 Kleinbuchstaben
|
|
password_chars.extend(random.choices(string.ascii_lowercase, k=2))
|
|
|
|
# Mindestens 2 Großbuchstaben
|
|
password_chars.extend(random.choices(string.ascii_uppercase, k=2))
|
|
|
|
# Mindestens 2 Zahlen
|
|
password_chars.extend(random.choices(string.digits, k=2))
|
|
|
|
# Mindestens 2 Sonderzeichen
|
|
special_chars = "!@#$%^&*"
|
|
password_chars.extend(random.choices(special_chars, k=2))
|
|
|
|
# Fülle mit zufälligen Zeichen auf
|
|
remaining_length = length - len(password_chars)
|
|
all_chars = string.ascii_letters + string.digits + special_chars
|
|
password_chars.extend(random.choices(all_chars, k=remaining_length))
|
|
|
|
# Mische die Zeichen
|
|
random.shuffle(password_chars)
|
|
|
|
return ''.join(password_chars)
|
|
|
|
@staticmethod
|
|
def is_valid_gmail_address(email: str) -> bool:
|
|
"""
|
|
Prüft ob eine Gmail-Adresse gültig ist
|
|
"""
|
|
if not email.endswith("@gmail.com"):
|
|
return False
|
|
|
|
username = email.split("@")[0]
|
|
|
|
# Gmail-Regeln:
|
|
# - 6-30 Zeichen
|
|
# - Buchstaben, Zahlen und Punkte
|
|
# - Muss mit Buchstabe oder Zahl beginnen
|
|
# - Kein Punkt am Anfang oder Ende
|
|
# - Keine aufeinanderfolgenden Punkte
|
|
|
|
if len(username) < 6 or len(username) > 30:
|
|
return False
|
|
|
|
if not username[0].isalnum() or not username[-1].isalnum():
|
|
return False
|
|
|
|
if ".." in username:
|
|
return False
|
|
|
|
# Prüfe erlaubte Zeichen
|
|
for char in username:
|
|
if not (char.isalnum() or char == "."):
|
|
return False
|
|
|
|
return True
|
|
|
|
@staticmethod
|
|
def format_phone_for_google(phone: str, country_code: str = "+1") -> str:
|
|
"""
|
|
Formatiert eine Telefonnummer für Google
|
|
"""
|
|
# Entferne alle nicht-numerischen Zeichen
|
|
phone_digits = ''.join(c for c in phone if c.isdigit())
|
|
|
|
# Wenn die Nummer bereits mit Ländercode beginnt
|
|
if phone.startswith("+"):
|
|
return phone
|
|
|
|
# Füge Ländercode hinzu
|
|
return f"{country_code}{phone_digits}" |