Untitled
unknown
plain_text
a year ago
2.0 kB
5
Indexable
import re
import datetime
import random
import string
while True: #Validation for first name.
first_name = input("Enter your first name: ")
if not first_name.isalpha():
print("Invalid first name. Please use only letters.")
continue
break
while True: #Validation for last name.
last_name = input("Enter your last name: ")
if not last_name.isalpha():
print("Invalid last name. Please use only letters.")
continue
break
def validate_date(date_str): #Validates the date format and checks if the user is 18 years old or older.
try:
date_obj = datetime.datetime.strptime(date_str, "%d/%m/%Y").date()
today = datetime.date.today()
age = today.year - date_obj.year - ((today.month, today.day) < (date_obj.month, date_obj.day))
if age >= 18:
return date_obj
else:
print("You must be 18 years or older to register.")
return None
except ValueError:
print("Invalid date format. Please use dd/mm/yyyy.")
return None
while True: #Takes input for the date of birth.
date_of_birth = input("Enter your date of birth (dd/mm/yyyy): ")
validated_date = validate_date(date_of_birth)
if validated_date:
break
def generate_password(length=8): #generates a random temporary password with at least one uppercase, one lowercase, and one digit.
while True:
password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))
if any(c.isupper() for c in password) and any(c.islower() for c in password) and any(c.isdigit() for c in password):
return password
password = generate_password()
user_id = first_name[:3].ljust(3, 'x') + last_name[:3].lower().ljust(3, 'x') + str(validated_date.year) #make a User ID following the criteria.
print("\n--- User Information ---")
print(f"Full Name: {first_name} {last_name}")
print(f"User ID: {user_id}")
print(f"Temporary Password: {password}")Editor is loading...
Leave a Comment