flask-httpauth: How is get_password decorator meant to work for basic-auth?

微笑、不失礼 提交于 2019-12-04 14:44:06

I'm the developer of Flask-HTTPAuth. Sorry I missed this question.

I just released a new version that gives you a way to use your custom function to verify a password. Instead of defining get_password and hash_password callbacks you can now use a verify_password callback that leaves the password verification completely up to you. For example, in your case you would use this callback:

@auth.verify_password
def verify_password(email, password):
    return check_auth(email, password)

I hope this helps!

I just realized this questions remained unanswered.

I am sure the project flask-httpauth is great for cases, where you intend to use md5 hash.

But as in my case, if you use sha256_crypt you can't make it work with this extension, due the way it works. (See my updated question)

What I ended up doing is to use this snippet written by the maker of flask.

The method check_auth is exactly what I needed as it returns boolean.

In my case I have defined it like this to make it work with sha256_crypt

def check_auth(email, password):
    em_login_provider = ndb.Key('AuthProvider', get_provider_id(constants.EMAIL, email)).get()        
    if em_login_provider and em_login_provider.active:
        user = em_login_provider.user                
        if user and verify_password(password, user.password_hash, user.password_hash_version):
            return True
    return False
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!