+ 1
Do not understand this Password Validation solution.
5 Antworten
+ 3
This code shouldn't actually pass, but it does. It should be;
import re
pswd = input()
special = re.sub("[!@#$%&*]","", pswd)
nums = re.sub("[\d]","", pswd)
if len(pswd) < 7 or len(special) > len(pswd)-2 or len(nums) > len(pswd)-2:
print ("Weak")
else :
print ("Strong")
re.sub(pattern, replacement, string)
Will return the string with the replacement in place of anywhere the pattern is found.
So for;
special = re.sub("[!@#$%&*]","", pswd)
Where pswd = @hsg18!jhd
special should be equal to hsg18jhd. Note that the matching characters have been removed by replacing them with empty strings. Thus making the length of the new String shorter than the original. This is likewise done with the digits.
+ 2
Well, ChaoticDawg. Your explanation seems reasonable. Thanks.
+ 1
import re
pswd = input()
special = re.sub("[!@#$%&*]","", pswd)
nums = re.sub("[\d]","", pswd)
if len(pswd) < 7 or len(special) == len(pswd) or len(nums) == len(pswd):
print ("Weak")
else :
print ("Strong")
+ 1
Above is the solution for Password Validation Problem. Yet i do not understand how the condition presumes that there will be 2 numbers and 2 special characters.
+ 1
At my point of view(wrong of course) the condition guarantees only 1 number and 1 special char.