Password hashing and verification
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
add a comment |
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
add a comment |
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
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
python python-3.x hash
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
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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))
Oh, didnt catch it, you are right, thanks, its working now
– Fred O.
Nov 15 '18 at 22:38
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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))
Oh, didnt catch it, you are right, thanks, its working now
– Fred O.
Nov 15 '18 at 22:38
add a comment |
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))
Oh, didnt catch it, you are right, thanks, its working now
– Fred O.
Nov 15 '18 at 22:38
add a comment |
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))
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))
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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