0% found this document useful (0 votes)
2 views

task10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

task10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mian Ayaan

22p-9149

class InvalidUsernameError(Exception):

pass

class WeakPasswordError(Exception):

pass

class AgeRestrictionError(Exception):

pass

import re

def validate_username(username):

if len(username) < 5 or not username.isalnum():

raise InvalidUsernameError("Username must be at least 5 characters long and contain only alphanumeric characters.")

def validate_password(password):

if (len(password) < 8 or

not re.search(r"[A-Z]", password) or

not re.search(r"[a-z]", password) or

not re.search(r"[0-9]", password)):

raise WeakPasswordError("Password must be at least 8 characters long and include at least one uppercase letter, one
lowercase letter, and one number.")

def validate_age(age):

if age < 18:

raise AgeRestrictionError("You must be at least 18 years old to register.")

def register_user():

while True:

try:

username = input("Enter username: ")

validate_username(username)
password = input("Enter password: ")

validate_password(password)

age = int(input("Enter age: "))

validate_age(age)

print("Registration successful")

break

except InvalidUsernameError as e:

print(f"Invalid username: {e}. Try again.")

except WeakPasswordError as e:

print(f"Weak password: {e}. Try again.")

except AgeRestrictionError as e:

print(f"Age restriction: {e}. Try again.")

finally:

print("Registration process complete.")

register_user()

You might also like