Test case errors for Validation Script for Emails and Passwords program

I am doing the following task:

Write a program for Master Your Credentials: A Tricky Validation Script for Emails and Passwords

Instructions

  1. Get the input their email address
  2. Use validate_email() to check the email format.
  3. Get the input their password.
  4. Use validate_password() to check the password strength.
  5. Continue prompting and validating until both email and password are valid.

Notes

  1. The email must have one ‘@’ and at least one in the domain part.
  2. validate_email() ensures the email format is correct.
  3. The password must be at least 8 characters long.
  4. validate_password() checks for length, digits, and letters.
  5. The program keeps asking for input until both email and password are valid.

Sample Input:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[email protected]
password@123
</code>
<code>[email protected] password@123 </code>
[email protected] 
password@123

Sample Output:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Email and password are valid.
Validation process completed.
</code>
<code>Email and password are valid. Validation process completed. </code>
Email and password are valid. 
Validation process completed.

This is my attempt:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import re
def validate_email(email):
if not email:
raise ValueError("Email cannot be empty")
pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$"
if re.match(pattern, email):
return True
return False
def validate_password(password):
if not password:
raise ValueError("Password cannot be empty")
pattern = r"^(?=.*[a-zA-Z])(?=.*d).{8,}$"
if re.match(pattern, password):
return True
return False
def main():
while True:
try:
email = input("Enter your email address: ")
if not validate_email(email):
print("Invalid email format. Please ensure the email has exactly one '@' and at least one '.' in the domain part.")
continue
password = input("Enter your password: ")
if not validate_password(password):
print("Invalid password. Please ensure the password is at least 8 characters long and includes at least one digit and one letter.")
continue
print("Email and password are valid. Validation process completed.")
break
except ValueError as e:
print(f"Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
if __name__ == "__main__":
main()
</code>
<code>import re def validate_email(email): if not email: raise ValueError("Email cannot be empty") pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$" if re.match(pattern, email): return True return False def validate_password(password): if not password: raise ValueError("Password cannot be empty") pattern = r"^(?=.*[a-zA-Z])(?=.*d).{8,}$" if re.match(pattern, password): return True return False def main(): while True: try: email = input("Enter your email address: ") if not validate_email(email): print("Invalid email format. Please ensure the email has exactly one '@' and at least one '.' in the domain part.") continue password = input("Enter your password: ") if not validate_password(password): print("Invalid password. Please ensure the password is at least 8 characters long and includes at least one digit and one letter.") continue print("Email and password are valid. Validation process completed.") break except ValueError as e: print(f"Error: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == "__main__": main() </code>
import re
def validate_email(email):
    if not email:
        raise ValueError("Email cannot be empty")

    pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$"
    if re.match(pattern, email):
        return True
    return False

def validate_password(password):
    if not password:
        raise ValueError("Password cannot be empty")
    pattern = r"^(?=.*[a-zA-Z])(?=.*d).{8,}$"
    if re.match(pattern, password):
        return True
    return False

def main():
    while True:
        try:
            email = input("Enter your email address: ")
            if not validate_email(email):
                print("Invalid email format. Please ensure the email has exactly one '@' and at least one '.' in the domain part.")
                continue
            password = input("Enter your password: ")
            if not validate_password(password):
                print("Invalid password. Please ensure the password is at least 8 characters long and includes at least one digit and one letter.")
                continue
            print("Email and password are valid. Validation process completed.")
            break
        except ValueError as e:
            print(f"Error: {e}")
        except Exception as e:
            print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

There are test cases:

TestCase 1:
Purpose: Handling errors and exceptions.
Hint: Ensure your email has exactly one ‘@’ and at least one ‘.’ in the domain part.

TestCase2:
Purpose: Handling errors and exceptions.
Hint: Verify the email’s username (before ‘@’) and domain (after ‘@’) are not empty.

TestCase3:
Purpose: Handling errors and exceptions.
Hint: Ensure your password is at least 8 characters long.

TestCase4:
Purpose: Handling errors and exceptions.
Hint: Include at least one digit and one letter in your password.

TestCase5:
Purpose: Handling errors and exceptions.
Hint: Pay attention to the error messages to understand what needs to be corrected.

The test cases 2, 3 and 4 have failed. What is going wrong here?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật