Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A website requires the users to input username and password to register. Write a program to check the validity of password input by users (using tuples only) Following are the criteria for checking the password: 1. At least 1 letter between [a-z] 2. At least 1 number between [0-9] 1. At least 1 letter between [A-Z] 3. At least 1 character from [$#@] 4. Minimum length of transaction password: 6 5. Maximum length of transaction password: 12 Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. Passwords that match the criteria are to be printed, each separated by a comma. If none of the password is valid, you should print "invalid"


What I have tried:

Python
p=list(input())
while len(p)>0:
    ps=[]
    for i in range(len(p)-1):
        if p[i]==",":
            p.remove(p[i])
            break
        else:
            ps.append(p[i])
            p.remove(p[i])
    for k in ps:
        if len(ps)>5 or len(ps)<13:
            if k.isalpha() or k.isdigit() or (k in ["@","#","$"]):
                print(k,end="")
            else:
                break
        else:
            break
Posted
Updated 24-Dec-22 0:05am
v2
Comments
OriginalGriff 24-Dec-22 0:12am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Member 15627495 24-Dec-22 0:49am    
as there are a lot of requirements for the password checking, go close about 'regular expression' with a accurate 'search pattern' dedicated to the need.
you'll write in 3 lines of code instead of 40.

Python
if len(ps)>5 or len(ps)<13:

That expression will succeed if the length is any value greater than 5 (i.e. 6 to infinity), or any value less than 13 (i.e. 12 to minus infinity). The test should be for expression 1 AND expression 2:
Python
if len(ps)>5 and len(ps)<13:
 
Share this answer
 
Comments
CPallini 24-Dec-22 6:02am    
5.
To extend Richard's observation, you are practically using OR everywhere AND is required: the input password must meet ALL the requirements, while your code is happy if any of them is met.
 
Share this answer
 
Comments
Richard MacCutchan 24-Dec-22 6:21am    
5 to you, and buon Natale.
CPallini 24-Dec-22 7:18am    
Grazie!
Merry Christmas to you and your family.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900