program checking for password strength (and/or operators aren't working/checking for symbols in a string?)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I am making a password program that checks for the strength of a password according to its length and how many uppercase /lowercase letters, numbers, and symbols there are.



The following is the program that I have so far, however whenever I enter a password that should be returned as 'medium', it doesn't work, and instead I am given either 'weak' or 'strong'.



Furthermore, I do not know how to check for symbols in a string. Any suggestions on how to achieve this and achieve the program? I only ask for simple explanations and suggestions, as I am only a beginner in middle school.



Thank you so much for the help.



password = None

print()
print("nYour password should be between 6 and 12 characters .")
print()

password=(input("Please enter your password : "))

numbers= sum(1 for c in password if c.isdigit())
uppercase= sum(1 for c in password if c.isupper())
lowercase= sum(1 for c in password if c.islower())

if len(password) <6:
print("ntThe password is too short .")
print("tTry a longer password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password) >12:
print("ntThe password is too long .")
print("tTry a shorter password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password)>=6 and len(password)<=12:

if password.lower()== password or password.upper()==password or password.isdigit()==password:
print("ntYour password is weak . ")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

elif password.lower()== password and password.upper()==password or password.isalnum()==password:
print("ntYour password is medium .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

else:
password.lower()== password and password.upper()==password and password.isalnum()==password
print ("ntYour password is strong .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)









share|improve this question

























  • If you want a password to be secure, why would you disallow it for being longer than 12 characters?

    – khelwood
    Nov 23 '18 at 18:08






  • 1





    password.isalnum() returns True or False, it can't be equal to password.

    – Alex Hall
    Nov 23 '18 at 18:19


















1















I am making a password program that checks for the strength of a password according to its length and how many uppercase /lowercase letters, numbers, and symbols there are.



The following is the program that I have so far, however whenever I enter a password that should be returned as 'medium', it doesn't work, and instead I am given either 'weak' or 'strong'.



Furthermore, I do not know how to check for symbols in a string. Any suggestions on how to achieve this and achieve the program? I only ask for simple explanations and suggestions, as I am only a beginner in middle school.



Thank you so much for the help.



password = None

print()
print("nYour password should be between 6 and 12 characters .")
print()

password=(input("Please enter your password : "))

numbers= sum(1 for c in password if c.isdigit())
uppercase= sum(1 for c in password if c.isupper())
lowercase= sum(1 for c in password if c.islower())

if len(password) <6:
print("ntThe password is too short .")
print("tTry a longer password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password) >12:
print("ntThe password is too long .")
print("tTry a shorter password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password)>=6 and len(password)<=12:

if password.lower()== password or password.upper()==password or password.isdigit()==password:
print("ntYour password is weak . ")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

elif password.lower()== password and password.upper()==password or password.isalnum()==password:
print("ntYour password is medium .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

else:
password.lower()== password and password.upper()==password and password.isalnum()==password
print ("ntYour password is strong .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)









share|improve this question

























  • If you want a password to be secure, why would you disallow it for being longer than 12 characters?

    – khelwood
    Nov 23 '18 at 18:08






  • 1





    password.isalnum() returns True or False, it can't be equal to password.

    – Alex Hall
    Nov 23 '18 at 18:19














1












1








1








I am making a password program that checks for the strength of a password according to its length and how many uppercase /lowercase letters, numbers, and symbols there are.



The following is the program that I have so far, however whenever I enter a password that should be returned as 'medium', it doesn't work, and instead I am given either 'weak' or 'strong'.



Furthermore, I do not know how to check for symbols in a string. Any suggestions on how to achieve this and achieve the program? I only ask for simple explanations and suggestions, as I am only a beginner in middle school.



Thank you so much for the help.



password = None

print()
print("nYour password should be between 6 and 12 characters .")
print()

password=(input("Please enter your password : "))

numbers= sum(1 for c in password if c.isdigit())
uppercase= sum(1 for c in password if c.isupper())
lowercase= sum(1 for c in password if c.islower())

if len(password) <6:
print("ntThe password is too short .")
print("tTry a longer password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password) >12:
print("ntThe password is too long .")
print("tTry a shorter password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password)>=6 and len(password)<=12:

if password.lower()== password or password.upper()==password or password.isdigit()==password:
print("ntYour password is weak . ")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

elif password.lower()== password and password.upper()==password or password.isalnum()==password:
print("ntYour password is medium .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

else:
password.lower()== password and password.upper()==password and password.isalnum()==password
print ("ntYour password is strong .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)









share|improve this question
















I am making a password program that checks for the strength of a password according to its length and how many uppercase /lowercase letters, numbers, and symbols there are.



The following is the program that I have so far, however whenever I enter a password that should be returned as 'medium', it doesn't work, and instead I am given either 'weak' or 'strong'.



Furthermore, I do not know how to check for symbols in a string. Any suggestions on how to achieve this and achieve the program? I only ask for simple explanations and suggestions, as I am only a beginner in middle school.



Thank you so much for the help.



password = None

print()
print("nYour password should be between 6 and 12 characters .")
print()

password=(input("Please enter your password : "))

numbers= sum(1 for c in password if c.isdigit())
uppercase= sum(1 for c in password if c.isupper())
lowercase= sum(1 for c in password if c.islower())

if len(password) <6:
print("ntThe password is too short .")
print("tTry a longer password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password) >12:
print("ntThe password is too long .")
print("tTry a shorter password .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers: ", numbers)

if len(password)>=6 and len(password)<=12:

if password.lower()== password or password.upper()==password or password.isdigit()==password:
print("ntYour password is weak . ")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

elif password.lower()== password and password.upper()==password or password.isalnum()==password:
print("ntYour password is medium .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)

else:
password.lower()== password and password.upper()==password and password.isalnum()==password
print ("ntYour password is strong .")
print("ntLowercase Letters : ", lowercase)
print("tUppercase Letters : ", uppercase)
print("tNumbers : ", numbers)






python python-3.x passwords






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 14 at 11:53









Cœur

19.4k10116155




19.4k10116155










asked Nov 23 '18 at 18:06









Aidyn Despiau-VazquezAidyn Despiau-Vazquez

62




62













  • If you want a password to be secure, why would you disallow it for being longer than 12 characters?

    – khelwood
    Nov 23 '18 at 18:08






  • 1





    password.isalnum() returns True or False, it can't be equal to password.

    – Alex Hall
    Nov 23 '18 at 18:19



















  • If you want a password to be secure, why would you disallow it for being longer than 12 characters?

    – khelwood
    Nov 23 '18 at 18:08






  • 1





    password.isalnum() returns True or False, it can't be equal to password.

    – Alex Hall
    Nov 23 '18 at 18:19

















If you want a password to be secure, why would you disallow it for being longer than 12 characters?

– khelwood
Nov 23 '18 at 18:08





If you want a password to be secure, why would you disallow it for being longer than 12 characters?

– khelwood
Nov 23 '18 at 18:08




1




1





password.isalnum() returns True or False, it can't be equal to password.

– Alex Hall
Nov 23 '18 at 18:19





password.isalnum() returns True or False, it can't be equal to password.

– Alex Hall
Nov 23 '18 at 18:19












1 Answer
1






active

oldest

votes


















0














Welcome to Stack Overflow Aidyn. There are a few problems that I see with your code.





The condition



password.lower()== password and password.upper()==password or password.isalnum()==password


won't ever happen. The first part password.lower()== password checks if the password is all lowercase. The next part password.upper()==password checks if it is all uppercase. The password can't be all lowercase and all uppercase at the same time.





password.isalnum() returns True or False. So instead of doing password.isalnum()==password, you would check if password.isalnum()==True





The line



password.lower()== password and password.upper()==password and password.isalnum()==password



Is not inside of an elif condition, so it doesn't matter if the result is True or False, it doesn't have any affect on the program.





Perhaps what you want to do is



   # If the password contains only lowercase characters or only uppercase or only digits, it is weak
if password.lower() == password or password.upper() == password or password.isdigit() == password:
...

# Otherwise, if the password does not have any symbols, it is medium strength
elif password.isalnum():
...

# Otherwise, it's strong.
else:
...




You can check for the number of symbols by doing



symbols = sum(1 for c in password if not c.isalnum())





share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451241%2fprogram-checking-for-password-strength-and-or-operators-arent-working-checking%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Welcome to Stack Overflow Aidyn. There are a few problems that I see with your code.





    The condition



    password.lower()== password and password.upper()==password or password.isalnum()==password


    won't ever happen. The first part password.lower()== password checks if the password is all lowercase. The next part password.upper()==password checks if it is all uppercase. The password can't be all lowercase and all uppercase at the same time.





    password.isalnum() returns True or False. So instead of doing password.isalnum()==password, you would check if password.isalnum()==True





    The line



    password.lower()== password and password.upper()==password and password.isalnum()==password



    Is not inside of an elif condition, so it doesn't matter if the result is True or False, it doesn't have any affect on the program.





    Perhaps what you want to do is



       # If the password contains only lowercase characters or only uppercase or only digits, it is weak
    if password.lower() == password or password.upper() == password or password.isdigit() == password:
    ...

    # Otherwise, if the password does not have any symbols, it is medium strength
    elif password.isalnum():
    ...

    # Otherwise, it's strong.
    else:
    ...




    You can check for the number of symbols by doing



    symbols = sum(1 for c in password if not c.isalnum())





    share|improve this answer






























      0














      Welcome to Stack Overflow Aidyn. There are a few problems that I see with your code.





      The condition



      password.lower()== password and password.upper()==password or password.isalnum()==password


      won't ever happen. The first part password.lower()== password checks if the password is all lowercase. The next part password.upper()==password checks if it is all uppercase. The password can't be all lowercase and all uppercase at the same time.





      password.isalnum() returns True or False. So instead of doing password.isalnum()==password, you would check if password.isalnum()==True





      The line



      password.lower()== password and password.upper()==password and password.isalnum()==password



      Is not inside of an elif condition, so it doesn't matter if the result is True or False, it doesn't have any affect on the program.





      Perhaps what you want to do is



         # If the password contains only lowercase characters or only uppercase or only digits, it is weak
      if password.lower() == password or password.upper() == password or password.isdigit() == password:
      ...

      # Otherwise, if the password does not have any symbols, it is medium strength
      elif password.isalnum():
      ...

      # Otherwise, it's strong.
      else:
      ...




      You can check for the number of symbols by doing



      symbols = sum(1 for c in password if not c.isalnum())





      share|improve this answer




























        0












        0








        0







        Welcome to Stack Overflow Aidyn. There are a few problems that I see with your code.





        The condition



        password.lower()== password and password.upper()==password or password.isalnum()==password


        won't ever happen. The first part password.lower()== password checks if the password is all lowercase. The next part password.upper()==password checks if it is all uppercase. The password can't be all lowercase and all uppercase at the same time.





        password.isalnum() returns True or False. So instead of doing password.isalnum()==password, you would check if password.isalnum()==True





        The line



        password.lower()== password and password.upper()==password and password.isalnum()==password



        Is not inside of an elif condition, so it doesn't matter if the result is True or False, it doesn't have any affect on the program.





        Perhaps what you want to do is



           # If the password contains only lowercase characters or only uppercase or only digits, it is weak
        if password.lower() == password or password.upper() == password or password.isdigit() == password:
        ...

        # Otherwise, if the password does not have any symbols, it is medium strength
        elif password.isalnum():
        ...

        # Otherwise, it's strong.
        else:
        ...




        You can check for the number of symbols by doing



        symbols = sum(1 for c in password if not c.isalnum())





        share|improve this answer















        Welcome to Stack Overflow Aidyn. There are a few problems that I see with your code.





        The condition



        password.lower()== password and password.upper()==password or password.isalnum()==password


        won't ever happen. The first part password.lower()== password checks if the password is all lowercase. The next part password.upper()==password checks if it is all uppercase. The password can't be all lowercase and all uppercase at the same time.





        password.isalnum() returns True or False. So instead of doing password.isalnum()==password, you would check if password.isalnum()==True





        The line



        password.lower()== password and password.upper()==password and password.isalnum()==password



        Is not inside of an elif condition, so it doesn't matter if the result is True or False, it doesn't have any affect on the program.





        Perhaps what you want to do is



           # If the password contains only lowercase characters or only uppercase or only digits, it is weak
        if password.lower() == password or password.upper() == password or password.isdigit() == password:
        ...

        # Otherwise, if the password does not have any symbols, it is medium strength
        elif password.isalnum():
        ...

        # Otherwise, it's strong.
        else:
        ...




        You can check for the number of symbols by doing



        symbols = sum(1 for c in password if not c.isalnum())






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 19:08

























        answered Nov 23 '18 at 18:18









        Mr. MeMr. Me

        3,33012337




        3,33012337
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451241%2fprogram-checking-for-password-strength-and-or-operators-arent-working-checking%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy