How to make a password validator without the use of the any

0 votes
Dec 7, 2020 in Python by anonymous
• 120 points
455 views

1 answer to this question.

0 votes

Hi, @There,

Regarding your query I would suggest you go through this.

Creating a password validator without using any external libraries involves checking for certain conditions that you define for a valid password. You can do this using basic Python programming constructs. Here's an example of a password validator function in Python:

def password_validator(password):
    if len(password) < 8:
        return "Password must be at least 8 characters long."

    has_upper = False
    has_lower = False
    has_digit = False
    has_special_char = False

    for char in password:
        if char.isupper():
            has_upper = True
        elif char.islower():
            has_lower = True
        elif char.isdigit():
            has_digit = True
        elif not char.isalnum():
            has_special_char = True

    if not has_upper:
        return "Password must contain at least one uppercase letter."
    if not has_lower:
        return "Password must contain at least one lowercase letter."
    if not has_digit:
        return "Password must contain at least one digit."
    if not has_special_char:
        return "Password must contain at least one special character."

    return "Password is valid."

# Example usage:
password = input("Enter your password: ")
result = password_validator(password)
print(result)

This function checks for:

  • Minimum length of 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one digit
  • At least one special character (non-alphanumeric)

You can modify these rules based on your specific requirements. To use the function, just call password_validator with the password string as an argument.

answered Dec 8, 2020 by Gitika
• 65,910 points

Related Questions In Python

0 votes
1 answer

How to get the size of a string in Python?

If you are talking about the length ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,450 points
1,082 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,270 points
1,600 views
–1 vote
2 answers
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21, 2019 in Python by Nymeria
• 3,560 points
7,709 views
0 votes
1 answer

How to find the index of a particular value in a dataframe?

First, use the dataframe to match the ...READ MORE

answered Apr 8, 2019 in Python by Esha
274,673 views
0 votes
1 answer

How to print the index of a Pandas Dataframe?

You can do this using the code ...READ MORE

answered May 13, 2019 in Python by Usha
21,522 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
18,565 views
0 votes
1 answer

How to count the number of elements in a list?

To count the number of elements of ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
4,621 views
0 votes
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,040 points
184,423 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP