GithubHelp home page GithubHelp logo

Comments (4)

ddorian avatar ddorian commented on July 28, 2024

Don't use md5 for password hashing. Use bcrypt.

from flask-mongoengine.

houmie avatar houmie commented on July 28, 2024

Is this the reason it fails? Would you kindly give me an example? thanks

from flask-mongoengine.

ddorian avatar ddorian commented on July 28, 2024

No. Use bcrypt. Flask-bcrypt

After active=True in init try adding (_args, *_kwargs) ?
Also WHY have you overrided init?

The way i did it is::::::pseudopython

class User(Document):
    password_hash = StringField()
    new_password = StringField()

    def save():
        if self.new_password:
            self.password_hash = bcrypt(self.new_password)
            self.new_password = None
        super. Document.save()

from flask-mongoengine.

allanlei avatar allanlei commented on July 28, 2024

@houmie Yes, you are correct in that overriding __init__ is the problem and you didn't call super(). If you take a look at monogoengine.base.document.BaseDocument, it does quite a few things in its __init__, setting field values being one of them.

Regarding the actual problem, the error message says exactly what the problem is. Your __init__ didn't accept password_hash keyword.

Though using md5 or bcrypt is not related to the problem, another suggestion for setting a password hash is to do something similar to what Django does.

class User(...):
   def set_password(self, raw_password, hasher=bcrypt, salt_length=1234):
      self.password_hash = hasher(raw_password, salt_length)

user = User.objects.get(email=email)   # or User(email=email)
user.set_password('password123')
user.save()

from flask-mongoengine.

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.