Python werkzeug.security.check_password_hash() Examples

The following are 30 code examples of werkzeug.security.check_password_hash(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module werkzeug.security , or try the search function .
Example #1
Source File: routes.py    From thewarden with MIT License 8 votes vote down vote up
def home():
    if current_user.is_authenticated:
        return redirect(url_for("portfolio.portfolio_main"))
    else:
        form = LoginForm()
        if form.validate_on_submit():
            user = User.query.filter_by(email=form.email.data).first()
            if user and check_password_hash(user.password, form.password.data):
                login_user(user, remember=form.remember.data)
                # The get method below is actually very helpful
                # it returns None if empty. Better than using [] for a dictionary.
                next_page = request.args.get("next")  # get the original page
                if next_page:
                    return redirect(next_page)
                else:
                    return redirect(url_for("main.home"))
            else:
                flash("Login failed. Please check e-mail and password",
                      "danger")

        return render_template("index.html", title="Login", form=form) 
Example #2
Source File: session.py    From spendb with GNU Affero General Public License v3.0 7 votes vote down vote up
def login():
    data = request_data()
    account = Account.by_name(data.get('login'))
    if account is not None:
        if check_password_hash(account.password, data.get('password')):
            login_user(account, remember=True)
            return jsonify({
                'status': 'ok',
                'message': _("Welcome back, %(name)s!", name=account.name)
            })
    return jsonify({
        'status': 'error',
        'errors': {
            'password': _("Incorrect user name or password!")
        }
    }, status=400) 
Example #3
Source File: views.py    From antminer-monitor with GNU General Public License v3.0 7 votes vote down vote up
def login():
    form = LoginForm()

    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            if check_password_hash(user.password_hash, form.password.data):
                print(form.remember.data)
                login_user(user, remember=form.remember.data)
                if 'next' in session:
                    next = session['next']
                    if is_safe_url(next):
                        return redirect(next)
                return redirect(url_for('antminer.miners'))
        flash("[ERROR] Invalid username or password", "error")
        return render_template('user/login.html', form=form)

    if current_user.is_authenticated:
        return redirect(url_for('antminer.miners'))

    return render_template('user/login.html', form=form) 
Example #4
Source File: user.py    From AutoLink with Apache License 2.0 7 votes vote down vote up
def __edit(self, args):

        result = {"status": "success", "msg": "用户信息修改成功"}
        user_path = self.app.config["AUTO_HOME"] + "/users/" + args["username"]
        if exists_path(user_path):
            config = json.load(codecs.open(user_path + '/config.json', 'r', 'utf-8'))
            if check_password_hash(config["passwordHash"], args["password"]):
                config["passwordHash"] = generate_password_hash(args["new_password"])
                config["fullname"] = args["fullname"]
                config["email"] = args["email"]
                json.dump(config, codecs.open(user_path + '/config.json', 'w', 'utf-8'))
            else:
                result["status"] = "fail"
                result["msg"] = "原始密码错误"
        else:
            result["status"] = "fail"
            result["msg"] = "用户不存在"

        return result 
Example #5
Source File: User.py    From AIOPS_PLATFORM with MIT License 7 votes vote down vote up
def verifyPassword(self, password):
        userObj = None
        if self.id is None:
            return(False)

        if password is None:
            return(False)

        else:
            userObj = self.getUserInfo()
            if check_password_hash(userObj.password, password):
                self.email = userObj.email
                self.group_list = userObj.group_list
                self.role_list = userObj.role_list
                self.business_system_list = userObj.business_system_list
                return(True)

    ## getUserInfo func 
Example #6
Source File: web.py    From calibre-web with GNU General Public License v3.0 7 votes vote down vote up
def load_user_from_auth_header(header_val):
    if header_val.startswith('Basic '):
        header_val = header_val.replace('Basic ', '', 1)
    basic_username = basic_password = ''
    try:
        header_val = base64.b64decode(header_val).decode('utf-8')
        basic_username = header_val.split(':')[0]
        basic_password = header_val.split(':')[1]
    except (TypeError, UnicodeDecodeError, binascii.Error):
        pass
    user = _fetch_user_by_name(basic_username)
    if user and config.config_login_type == constants.LOGIN_LDAP and services.ldap:
        if services.ldap.bind_user(str(user.password), basic_password):
            return user
    if user and check_password_hash(str(user.password), basic_password):
        return user
    return 
Example #7
Source File: routes.py    From thewarden with MIT License 7 votes vote down vote up
def login():
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            # The get method below is actually very helpful
            # it returns None if empty. Better than using [] for a dictionary.
            next_page = request.args.get("next")  # get the original page
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for("main.home"))
        else:
            flash("Login failed. Please check e-mail and password", "danger")

    return render_template("login.html", title="Login", form=form) 
Example #8
Source File: basic.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def check(self, uid=None, passwd=None):
        """:func:`burpui.misc.auth.basic.BasicLoader.check` verifies if the
        given password matches the given user settings.

        :param uid: User to authenticate
        :type uid: str

        :param passwd: Password
        :type passwd: str

        :returns: True if there is a match, otherwise False
        """
        self.load_users()
        if uid in self.users:
            if self.users[uid]['salted']:
                return check_password_hash(self.users[uid]['pwd'], passwd)
            else:
                return self.users[uid]['pwd'] == passwd
        return False 
Example #9
Source File: models.py    From elearning with MIT License 5 votes vote down vote up
def check_hash_password(self, password):
        return check_password_hash(self.u_password, password) 
Example #10
Source File: auth.py    From ukbrest with MIT License 5 votes vote down vote up
def verify_password(self, username, password):
        users_passwd = self.read_users_file()

        if users_passwd is None:
            return True

        if username in users_passwd:
            return check_password_hash(users_passwd.get(username), password)

        return False 
Example #11
Source File: models.py    From todoism with MIT License 5 votes vote down vote up
def validate_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #12
Source File: models.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #13
Source File: auth.py    From AutoLink with Apache License 2.0 5 votes vote down vote up
def post(self):
        args = self.parser.parse_args()
        username = args["username"]
        password = args["password"]
        app = current_app._get_current_object()
        user_path = app.config["AUTO_HOME"] + "/users/" + username
        if os.path.exists(user_path):
            user = json.load(codecs.open(user_path + '/config.json', 'r', 'utf-8'))
            if check_password_hash(user['passwordHash'], password):
                session['username'] = username
                return {"status": "success", "msg": "login success", "url": url_for('routes.dashboard')}, 201

        return {"status": "fail", "msg": "login fail", "url": url_for('routes.index')}, 201 
Example #14
Source File: chapter9_9.py    From Mastering-Python-Networking-Third-Edition with MIT License 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #15
Source File: models.py    From authy2fa-flask with MIT License 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #16
Source File: restauth.py    From maniwani with MIT License 5 votes vote down vote up
def _slip_check():
    if request.authorization is None:
        return None
    username = request.authorization.username
    slip = db.session.query(Slip).filter(Slip.name == username).one_or_none()
    if slip is None:
        return None
    password = request.authorization.password
    if check_password_hash(slip.pass_hash, password) is False:
        return None
    return slip 
Example #17
Source File: slip.py    From maniwani with MIT License 5 votes vote down vote up
def login():
    form_name = request.form["name"]
    password = request.form["password"]
    slip = db.session.query(Slip).filter(Slip.name == form_name).one_or_none()
    if slip:
        if check_password_hash(slip.pass_hash, password):
            make_session(slip)
            db.session.commit()
        else:
            flash("Incorrect username or password!")
    else:
        flash("Incorrect username or password!")
    return redirect(url_for("slip.landing")) 
Example #18
Source File: models.py    From CTF with MIT License 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #19
Source File: user.py    From flask-skeleton with Do What The F*ck You Want To Public License 5 votes vote down vote up
def check_password(self, password):
        return check_password_hash(self.password, password) 
Example #20
Source File: models.py    From antminer-monitor with GNU General Public License v3.0 5 votes vote down vote up
def check_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #21
Source File: models.py    From flask-pycon2014 with MIT License 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #22
Source File: models.py    From dash_on_flask with MIT License 5 votes vote down vote up
def check_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #23
Source File: channel_manager.py    From gdanmaku-server with GNU General Public License v3.0 5 votes vote down vote up
def verify_exam_passwd(self, password):
        if self.exam_passwd is None:
            return True
        return check_password_hash(self.exam_passwd, password) 
Example #24
Source File: channel_manager.py    From gdanmaku-server with GNU General Public License v3.0 5 votes vote down vote up
def verify_pub_passwd(self, password):
        if self.pub_passwd is None:
            return True
        return check_password_hash(self.pub_passwd, password) 
Example #25
Source File: channel_manager.py    From gdanmaku-server with GNU General Public License v3.0 5 votes vote down vote up
def verify_sub_passwd(self, password):
        return check_password_hash(self.sub_passwd, password) 
Example #26
Source File: hashed_user.py    From web_develop with GNU General Public License v3.0 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password, password) 
Example #27
Source File: models.py    From graphql-pynamodb with MIT License 5 votes vote down vote up
def check_password(self, password):
        return check_password_hash(self.password, password) 
Example #28
Source File: models.py    From BackManager with Apache License 2.0 5 votes vote down vote up
def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 
Example #29
Source File: basic.py    From burp-ui with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def change_password(self, user, passwd, old_passwd=None):
        """Change a user password"""
        self._setup_users()
        old_users = self.users
        self.load_users(True)
        current = self.users.get(
            user,
            old_users.get(user, None)
        )

        if not current:
            message = "user '{}' does not exist".format(user)
            self.logger.error(message)
            return False, message, NOTIF_ERROR

        if current['salted']:
            comp = check_password_hash
        else:
            def comp(x, y):
                return x == y

        curr = current['pwd']
        if old_passwd and not comp(curr, old_passwd):
            message = "unable to authenticate user '{}'".format(user)
            self.logger.error(message)
            return False, message, NOTIF_ERROR

        if comp(curr, passwd):
            message = 'password is the same'
            self.logger.warning(message)
            return False, message, NOTIF_WARN

        pwd = generate_password_hash(passwd)
        self.conf.options[self.section][user] = pwd
        self.conf.options.write()
        self.load_users(True)
        message = "user '{}' successfully updated".format(user)
        return True, message, NOTIF_OK 
Example #30
Source File: user.py    From walle-web with Apache License 2.0 5 votes vote down vote up
def verify_password(self, password):
        """
        检查密码是否正确
        :param password:
        :return:
        """
        if self.password is None:
            return False
        return check_password_hash(self.password, password)