+ 1

Do not understand this Password Validation solution.

Python

5th Sep 2021, 11:25 AM
Norberto Costa
Norberto Costa - avatar
5 Respostas
+ 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.
5th Sep 2021, 11:54 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Well, ChaoticDawg. Your explanation seems reasonable. Thanks.
5th Sep 2021, 12:39 PM
Norberto Costa
Norberto Costa - avatar
+ 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")
5th Sep 2021, 11:26 AM
Norberto Costa
Norberto Costa - avatar
+ 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.
5th Sep 2021, 11:28 AM
Norberto Costa
Norberto Costa - avatar
+ 1
At my point of view(wrong of course) the condition guarantees only 1 number and 1 special char.
5th Sep 2021, 11:35 AM
Norberto Costa
Norberto Costa - avatar