Giter Site home page Giter Site logo

ValueError: Invalid salt about bcrypt HOT 13 CLOSED

pyca avatar pyca commented on July 21, 2024
ValueError: Invalid salt

from bcrypt.

Comments (13)

shahram4m avatar shahram4m commented on July 21, 2024 1

Check the database for password field value. i think password value did not hashed in the table. then this error raised when user try to login.

from bcrypt.

charmander avatar charmander commented on July 21, 2024

Did you check self.password?

from bcrypt.

alanhamlett avatar alanhamlett commented on July 21, 2024

Yes, the check_password method looks like this and checks for unset/empty passwords on the first line:

    def check_password(self, password):
        if not self.password or not password:
            return False
        return bcrypt.check_password_hash(self.password, password)

from bcrypt.

charmander avatar charmander commented on July 21, 2024

What is the value of self.password when the error occurs?

from bcrypt.

alanhamlett avatar alanhamlett commented on July 21, 2024

I'm not sure of the exact value of self.password at the time of the error, but it must have been a Python2 unicode type because it was retrieved via Postgres from a VARCHAR(160) column. It could not have been None or blank as seen in the check_password method above. It would have been a hashed password value for a user (the past output from bcrypt.generate_password_hash(password)).

from bcrypt.

HendrikF avatar HendrikF commented on July 21, 2024

Sorry, mixed libraries...

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

InvalidSalt is what is raised if you supply a password that does not match the given bcrypt hash. Since this is a few months old I'm going to close it but if you're still having an issue feel free to reopen.

from bcrypt.

alanhamlett avatar alanhamlett commented on July 21, 2024

@reaperhulk why does the exception say invalid salt instead of invalid password? The docs say when supplying a password not matching the given bcrypt hash that bcrypt.check_password_hash should return None not raise an exception.

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

@alanhamlett Are you sure you're looking at the docs for this project? check_password_hash is not a function we provide. checkpw is a function py-bcrypt supplies, but right now bcrypt does not (although there's no reason why it couldn't since checkpw is just calling the same thing hashpw does but returning a different message).

from bcrypt.

alanhamlett avatar alanhamlett commented on July 21, 2024

Oh sorry that method was from Flask-Bcrypt which wraps this library. Maybe it's a bug in Flask-Bcrypt then.

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

I filed supporting checkpw as #74 so it may be in an upcoming release as well. It is definitely confusing that hashpw can both generate a new password hash and also verify a password against a pre-generated hash (and the failure case will raise InvalidSalt)

from bcrypt.

charmander avatar charmander commented on July 21, 2024

InvalidSalt is what is raised if you supply a password that does not match the given bcrypt hash. Since this is a few months old I'm going to close it but if you're still having an issue feel free to reopen.

This doesn’t seem to be the case:

>>> h = bcrypt.hashpw(b'password', bcrypt.gensalt(10))
>>> h
'$2b$10$asbns6WWho6TkeROkj6i6ekOCrI6oD0EZBb32n7NrmDFzhDl9E8fy'
>>> bcrypt.hashpw(b'test', h)
'$2b$10$asbns6WWho6TkeROkj6i6eCCbN64Jo282VVeqvo75SxJMtvl6arWi'

Tested with both bcrypt 2.0.0 and 3.0.0.

from bcrypt.

reaperhulk avatar reaperhulk commented on July 21, 2024

@charmander is entirely correct and my reading was nonsense.

hashpw takes either a salt OR a "hash" (which is the salt concatenated with the derived password hash). When you call hashpw with the hash it grabs the salt and creates a new hash with the given password and it's up to the caller to compare to see if the two hashes are equal. As of this moment (3.0.0 and below) you must do this comparison yourself, but #76 will do it on your behalf.

from bcrypt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.