Movatterモバイル変換


[0]ホーム

URL:


Open In App

Given a password, we have to categorize it as a strong or weak one. There are some checks that need to be met to be a strong password. For a weak password, we need to return the reason for it to be weak.Conditions to be fulfilled are:

Note: For checking the basic validations of a password,click here.Examples:

Input1 : Qggf!@ghf3Output1 : Strong Password!Input2 : aaabnil1guOutput2 : Weak Password: Same character repeats three or more times in a rowInput3 : GeeksforgeeksOutput3 : Weak Password: Same character repeats three or more times in a rowInput4 : Aasd!feasnmOutput4 : Weak password: Same string pattern repetitionInput5 : 772*hdf77Output5 : Weak password: Same string pattern repetitionInput6 : " "Output6 : Password cannot be a newline or space!

Below is the implementation. 

Python3
# Categorizing password as Strong or# Weak in Python using Regeximportre# Function to categorize passworddefpassword(v):# the password should not be a# newline or spaceifv=="\n"orv==" ":return"Password cannot be a newline or space!"# the password length should be in# between 9 and 20if9<=len(v)<=20:# checks for occurrence of a character# three or more times in a rowifre.search(r'(.)\1\1',v):return"Weak Password: Same character repeats three or more times in a row"# checks for occurrence of same string# pattern( minimum of two character length)# repeatingifre.search(r'(..)(.*?)\1',v):return"Weak password: Same string pattern repetition"else:return"Strong Password!"else:return"Password length must be 9-20 characters!"# Main methoddefmain():# Driver codeprint(password("Qggf!@ghf3"))print(password("Gggksforgeeks"))print(password("aaabnil1gu"))print(password("Aasd!feasn"))print(password("772*hd897"))print(password(" "))# Driver Codeif__name__=='__main__':main()

Output
Strong Password!Weak password: Same string pattern repetitionWeak Password: Same character repeats three or more times in a rowWeak password: Same string pattern repetitionStrong Password!Password cannot be a newline or space!

Time Complexity: O(N)  N is refers to the length of the input password string,
Auxiliary Space: O(1) 


Improve

Explore

Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp