Password hashing and verification










1















I'm trying to learn now about hashing and verification of passwords, I was told to use the module passlib and pbkdf2.
The code I was recommended was:



To Hash:



 from passlib.hash import pbkdf2_sha256 
hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)


To Authenticate:



from passlib.hash import pbkdf2_sha256
pbkdf2_sha256.verify("password", hash)


I think I understand all the code here, except for one thing, where would the Hash for any given password be stored, and mainly how to have the input for the password that i want to verify,
I tried using



password = input("Enter a password here: ")


That worked since I tried printing the hash, and each time i entered the same password, i got the same hash, so up to that point, everything is working.



now, i tried resetting password, by a new input, and then having the authentication code after it, thinking that I have set password as a new value, I should be able to get a False value each time i entered a password that does not match to the first one entered, yet, there, no matter the second input, returns True



here's the full code



from passlib.hash import pbkdf2_sha256

password = input("Enter a password:")
hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)
print(hash)

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

print(pbkdf2_sha256.verify("password", hash))


Then I tried setting the 2nd password as "password2" and that returns false always.










share|improve this question




























    1















    I'm trying to learn now about hashing and verification of passwords, I was told to use the module passlib and pbkdf2.
    The code I was recommended was:



    To Hash:



     from passlib.hash import pbkdf2_sha256 
    hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)


    To Authenticate:



    from passlib.hash import pbkdf2_sha256
    pbkdf2_sha256.verify("password", hash)


    I think I understand all the code here, except for one thing, where would the Hash for any given password be stored, and mainly how to have the input for the password that i want to verify,
    I tried using



    password = input("Enter a password here: ")


    That worked since I tried printing the hash, and each time i entered the same password, i got the same hash, so up to that point, everything is working.



    now, i tried resetting password, by a new input, and then having the authentication code after it, thinking that I have set password as a new value, I should be able to get a False value each time i entered a password that does not match to the first one entered, yet, there, no matter the second input, returns True



    here's the full code



    from passlib.hash import pbkdf2_sha256

    password = input("Enter a password:")
    hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)
    print(hash)

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

    print(pbkdf2_sha256.verify("password", hash))


    Then I tried setting the 2nd password as "password2" and that returns false always.










    share|improve this question


























      1












      1








      1








      I'm trying to learn now about hashing and verification of passwords, I was told to use the module passlib and pbkdf2.
      The code I was recommended was:



      To Hash:



       from passlib.hash import pbkdf2_sha256 
      hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)


      To Authenticate:



      from passlib.hash import pbkdf2_sha256
      pbkdf2_sha256.verify("password", hash)


      I think I understand all the code here, except for one thing, where would the Hash for any given password be stored, and mainly how to have the input for the password that i want to verify,
      I tried using



      password = input("Enter a password here: ")


      That worked since I tried printing the hash, and each time i entered the same password, i got the same hash, so up to that point, everything is working.



      now, i tried resetting password, by a new input, and then having the authentication code after it, thinking that I have set password as a new value, I should be able to get a False value each time i entered a password that does not match to the first one entered, yet, there, no matter the second input, returns True



      here's the full code



      from passlib.hash import pbkdf2_sha256

      password = input("Enter a password:")
      hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)
      print(hash)

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

      print(pbkdf2_sha256.verify("password", hash))


      Then I tried setting the 2nd password as "password2" and that returns false always.










      share|improve this question
















      I'm trying to learn now about hashing and verification of passwords, I was told to use the module passlib and pbkdf2.
      The code I was recommended was:



      To Hash:



       from passlib.hash import pbkdf2_sha256 
      hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)


      To Authenticate:



      from passlib.hash import pbkdf2_sha256
      pbkdf2_sha256.verify("password", hash)


      I think I understand all the code here, except for one thing, where would the Hash for any given password be stored, and mainly how to have the input for the password that i want to verify,
      I tried using



      password = input("Enter a password here: ")


      That worked since I tried printing the hash, and each time i entered the same password, i got the same hash, so up to that point, everything is working.



      now, i tried resetting password, by a new input, and then having the authentication code after it, thinking that I have set password as a new value, I should be able to get a False value each time i entered a password that does not match to the first one entered, yet, there, no matter the second input, returns True



      here's the full code



      from passlib.hash import pbkdf2_sha256

      password = input("Enter a password:")
      hash = pbkdf2_sha256.hash("password", rounds=20000, salt_size=16)
      print(hash)

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

      print(pbkdf2_sha256.verify("password", hash))


      Then I tried setting the 2nd password as "password2" and that returns false always.







      python python-3.x hash






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 20:33









      benvc

      6,4331827




      6,4331827










      asked Nov 15 '18 at 20:20









      Fred O.Fred O.

      114




      114






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You are hashing and verifying the text "password" rather than hashing and verifying the input. Minor change to your variable names to make it a bit clearer what you need to change:



          from passlib.hash import pbkdf2_sha256

          password_input = input("Enter a password:")
          hash = pbkdf2_sha256.hash(password_input, rounds=20000, salt_size=16)
          print(hash)

          password_confirm = input("please enter your password:")

          print(pbkdf2_sha256.verify(password_confirm, hash))





          share|improve this answer























          • Oh, didnt catch it, you are right, thanks, its working now

            – Fred O.
            Nov 15 '18 at 22:38











          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%2f53327313%2fpassword-hashing-and-verification%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














          You are hashing and verifying the text "password" rather than hashing and verifying the input. Minor change to your variable names to make it a bit clearer what you need to change:



          from passlib.hash import pbkdf2_sha256

          password_input = input("Enter a password:")
          hash = pbkdf2_sha256.hash(password_input, rounds=20000, salt_size=16)
          print(hash)

          password_confirm = input("please enter your password:")

          print(pbkdf2_sha256.verify(password_confirm, hash))





          share|improve this answer























          • Oh, didnt catch it, you are right, thanks, its working now

            – Fred O.
            Nov 15 '18 at 22:38















          0














          You are hashing and verifying the text "password" rather than hashing and verifying the input. Minor change to your variable names to make it a bit clearer what you need to change:



          from passlib.hash import pbkdf2_sha256

          password_input = input("Enter a password:")
          hash = pbkdf2_sha256.hash(password_input, rounds=20000, salt_size=16)
          print(hash)

          password_confirm = input("please enter your password:")

          print(pbkdf2_sha256.verify(password_confirm, hash))





          share|improve this answer























          • Oh, didnt catch it, you are right, thanks, its working now

            – Fred O.
            Nov 15 '18 at 22:38













          0












          0








          0







          You are hashing and verifying the text "password" rather than hashing and verifying the input. Minor change to your variable names to make it a bit clearer what you need to change:



          from passlib.hash import pbkdf2_sha256

          password_input = input("Enter a password:")
          hash = pbkdf2_sha256.hash(password_input, rounds=20000, salt_size=16)
          print(hash)

          password_confirm = input("please enter your password:")

          print(pbkdf2_sha256.verify(password_confirm, hash))





          share|improve this answer













          You are hashing and verifying the text "password" rather than hashing and verifying the input. Minor change to your variable names to make it a bit clearer what you need to change:



          from passlib.hash import pbkdf2_sha256

          password_input = input("Enter a password:")
          hash = pbkdf2_sha256.hash(password_input, rounds=20000, salt_size=16)
          print(hash)

          password_confirm = input("please enter your password:")

          print(pbkdf2_sha256.verify(password_confirm, hash))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 20:30









          benvcbenvc

          6,4331827




          6,4331827












          • Oh, didnt catch it, you are right, thanks, its working now

            – Fred O.
            Nov 15 '18 at 22:38

















          • Oh, didnt catch it, you are right, thanks, its working now

            – Fred O.
            Nov 15 '18 at 22:38
















          Oh, didnt catch it, you are right, thanks, its working now

          – Fred O.
          Nov 15 '18 at 22:38





          Oh, didnt catch it, you are right, thanks, its working now

          – Fred O.
          Nov 15 '18 at 22:38



















          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%2f53327313%2fpassword-hashing-and-verification%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







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3