: Write a Python function named "validate_password" that takes a string as input and checks if it is a valid password. A valid password should meet the following criteria: • It must be at least 8 characters long. • It must contain at least one uppercase letter, one lowercase letter, and one digit
时间: 2024-03-10 15:45:29 浏览: 18
Sure, here's an example implementation of the `validate_password` function in Python:
```python
def validate_password(password):
# Check length
if len(password) < 8:
return False
# Check for uppercase, lowercase, and digit
has_upper = False
has_lower = False
has_digit = False
for char in password:
if char.isupper():
has_upper = True
elif char.islower():
has_lower = True
elif char.isdigit():
has_digit = True
return has_upper and has_lower and has_digit
```
This function takes a string `password` as input and returns `True` if the password is valid, and `False` otherwise. It checks the length of the password and whether it contains at least one uppercase letter, one lowercase letter, and one digit. You can call this function with a password string to check if it meets the criteria for a valid password.