+ 1
[SOLVED] Help me solve this...
You're interviewing to join a security team. They want to see you build a password evaluator for your technical interview to validate the input. Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '
#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong My attempt:- https://code.sololearn.com/cNMR5d7EGcgI/?ref=app10 Antworten
+ 10
#MyCode
string = input()
num_count = 0
char_count = 0
char = ["!","@","#","quot;,"%","&","*"]
nums = ["1","2","3","4","5","6","7","8","9","0"]
for var in string:
if var in char:
char_count += 1
if var in nums:
num_count += 1
if (char_count>1 and num_count>1) and (len(string)>6):
print("Strong")
else:
print("Weak")
+ 4
Your code will always output Weak as
"in" operater checks only one value in a sequence and can't be mixed with "and" to check multiple values.
Hope It Helps You 😊
+ 2
Hacker Badshah Oh thanks I understood the logic too I'll write this code on my own now.
Thanks for the help, buddy 👍
+ 1
Can it be done using regex
+ 1
Swapnil Kamdi You asking or telling me? 😅😅
+ 1
Kêsh@v Obviously asking, I forgot to put question mark. I'm looking a code for this in regex method. Would you please help me out.
+ 1
nums='0123456789'
sp_characters='!@#$%&*'
password=str(input())
a=0
b=0
for i in range(len(sp_characters)):
for x in range(len(password )):
if sp_characters [i]==password[x]:
a+=1
for i in range(len(nums)):
for x in range(len(password)):
if nums[i]==password[x]:
b+=1
if a>=2 and b>=2 and len(password)>=7:
print('Strong')
else:
print('Weak')
0
Swapnil Kamdi I don't know bcz I've never practiced Regex :(
0
#Swift #swift
var myString = readLine() ?? ""
var ch_ = ["!", "@", "#", "quot;, "%", "&", "*"]
var sm_ = ["0","1","2","3","4","5","6","7","8","9"]
var ch = 0
var sm = 0
for i in myString{
if ch_.contains("\(i)"){
ch+=1
}else if sm_.contains("\(i)"){
sm+=1}
}
if sm>=2 && ch>=2 && myString.count>=7{
print("Strong")
}else{
print("Weak")
}
0
# my solution # python
password = input()
mot = len(password )
nb = ("0123456789")
special_caract = ('!', '@', '#', '#x27;, '%', '&', '*')
n=0
s=0
for i in password :
if i in nb :
n+=1
elif i in special_caract :
s+= 1
if n>1 and s >1 and mot >6:
print ("Strong")
else :
print ("Weak")