Computer Science, asked by Umar2654, 1 year ago

Write a program to validate given password in python

Answers

Answered by singhmahesh140
0
--------------Python Exercises, Practice and Solution: Write a Python program to check the validity of a password (input from users).-------------
i hope it will help you
Answered by fiercespartan
4

Let's say that for our password, we will need to have at least 1 upper case, at least 1 lower case and one number and at least one special character.

_____________________________________________

We will be using the following:

(1) .islower()

(2) .isupper()

(3) .isdigit()

(4) any()

(5) all()

______________________________________________

Special characters include : [@_!#$%^&*()<>?/\|}{~:]

- Before writing the requirements into a code, we will be taking a password input.

- We will first check for the lower case letters

- Then, check for upper case

- Check for the numbers

- And at last, check for the special characters.

If all the requirements are met, we print 'Password is valid' else, we print 'Please enter a new password' and we repeat the code again :)

_____________________________________________

CODE:

def password_checker():

   validator = []

   special_char = '[@_!#$%^&*()<>?/\|}{~:]'

   password = str(input('Enter the password:'))

   validator.append(any([x.islower() for x in password]))

   validator.append(any([x.isupper() for x in password]))

   validator.append(any([x.isdigit() for x in password]))

   validator.append(any([x in special_char for x in password]))

   if all(validator):

       print('Your password is valid')

   else:

       print('Please try your password again, check the requirements')

       password_checker()

password_checker()

______________________________________________

   

Similar questions