Develop a python function using regular expression for validating a password.Password should contain at least one capital letter, one number and one special character like @$!%*#?&Length of the password should be between 8 and 18.Sample Input:XdsE83&!2Sample Output:ValidSample Input:asDf#$Q$$Invalid
Question
Develop a python function using regular expression for validating a password.Password should contain at least one capital letter, one number and one special character like @QInvalid
Solution
Sure, here is a Python function that uses regular expressions to validate a password according to the rules you provided:
import re
def validate_password(password):
if len(password) < 8 or len(password) > 18:
return "Invalid"
elif not re.search("[A-Z]", password):
return "Invalid"
elif not re.search("[0-9]", password):
return "Invalid"
elif not re.search("[$@!%*#?&]", password):
return "Invalid"
else:
return "Valid"
# Test the function
print(validate_password("XdsE83&!2")) # Output: Valid
print(validate_password("asDf#$Q$$")) # Output: Invalid
This function first checks if the length of the password is between 8 and 18. If not, it returns "Invalid". Then it checks if the password contains at least one capital letter, one number, and one special character. If any of these checks fail, it returns "Invalid". If all checks pass, it returns "Valid".
Similar Questions
Python program to check the validity of username and password input by users
Check if a string is matching password requirements Sample inputProgram#123Sample outputSuccessfully Matched with the Password Requirements.ExplanationRead a string which should satisfy the password requirements.If the string satisfies the given requirements print "Successfully Matched with the Password Requirements." without double quotes.if not satisfied print "Not Matched with the Password Requirements." without the double quotes.Password Requirements :Atleast one Uppercase character.Atleast one Lowercase character.Atleast one special Character.Atleast one Number.The string should be more than 8 characters long. SAMPLE INPUT: Program#12SAMPLE OUTPUT:Successfully Matched with the Password Requirements.Note:Your code must be able to print the sample output from the provided sample input. However, your code is run against multiple hidden test cases. Therefore, your code must pass these hidden test cases to solve the problem statement.
A password must start with a letter, be at least 6 characters long, include a number, not include any whitespace, and include a special symbol. How many of the following passwords are valid?hello, goodbye, Maker1, dog!three, Oops_again, 1augh#3
Design a login form using HTML & JavaScript with following validations usingRegular Expression on username and password fields.1. Username and Password should not be both blank2. Username should not start with digit,_, @ or #3. Password length must be 8 to 16 characters
ou're working on a Bash script that needs to validate user input for a password. The script should check if the password meets certain criteria: it should be at least 8 characters long, contain both uppercase and lowercase letters, and include at least one number. Which code snippet correctly implements this password validation using a while loop?0.5 Markswhile true; doread -sp "Enter password: " passwordif [[ ${#password} -lt 8 || ! "$password" =~ [a-z] || ! "$password" =~ [A-Z] || ! "$password" =~ [0-9] ]]; thenecho "Invalid password. Please try again."elseecho "Password is valid."breakfidonewhile true; doread -sp "Enter password: " passwordif [[ ${#password} < 8 || ! "$password" =~ [a-z] || ! "$password" =~ [A-Z] || ! "$password" =~ [0-9] ]]; thenecho "Invalid password. Please try again."elseecho "Password is valid."breakfidonewhile true; doread -sp "Enter password: " passwordif [[ ${#password} -lt 8 || ! "$password" =~ [[:lower:]] || ! "$password" =~ [[:upper:]] || ! "$password" =~ [0-9] ]]; thenecho "Invalid password. Please try again."elseecho "Password is valid."breakfidonewhile true; doread -sp "Enter password: " passwordif [[ ${#password} -lt 8 || ! "$password" =~ [a-zA-Z] || ! "$password" =~ [0-9] ]]; thenecho "Invalid password. Please try again."elseecho "Password is valid."breakfidonewhile true; doread -sp "Enter password: " passwordif [[ ${#password} < 8 || ! "$password" =~ [[:lower:]] || ! "$password" =~ [[:upper:]] || ! "$password" =~ [[:digit:]] ]]; thenecho "Invalid password. Please try again."elseecho "Password is valid."breakfidone
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.