当前位置: 首页>>代码示例>>Python>>正文


Python security.generate_password_hash方法代码示例

本文整理汇总了Python中werkzeug.security.generate_password_hash方法的典型用法代码示例。如果您正苦于以下问题:Python security.generate_password_hash方法的具体用法?Python security.generate_password_hash怎么用?Python security.generate_password_hash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.security的用法示例。


在下文中一共展示了security.generate_password_hash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_user

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def add_user(cls, identifier: str, password: str, password_encrypted: bool = False) -> None:
        """新增用户。当用户已存在时,抛出ValueError。

        :param identifier: 学号或教工号
        :param password: 密码
        :param password_encrypted: 密码是否已经被加密过了(否则会被二次加密)
        """
        if not password_encrypted:
            password_hash = generate_password_hash(password)
        else:
            password_hash = password

        user = User(identifier=identifier, password=password_hash, create_time=datetime.datetime.now())

        db_session.add(user)
        try:
            db_session.commit()
        except IntegrityError as e:
            raise AlreadyRegisteredError from e 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:21,代码来源:user.py

示例2: _new_request

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def _new_request(cls, identifier: str, verification_method: str, status: str, password: str = None) -> str:
        """
        新增一条注册请求

        :param identifier: 学号/教工号
        :param verification_method: password or email
        :param status: status of the request
        :param password: if register by password, fill everyclass password here
        :return: the `request_id`
        """
        if verification_method not in (cls.METHOD_PASSWORD, cls.METHOD_EMAIL):
            raise ValueError("verification_method must be one of email and password")

        request_id = uuid.uuid4()

        extra_doc = {}
        if password:
            extra_doc.update({"password": generate_password_hash(password)})

        request = VerificationRequest(request_id=request_id, identifier=identifier, method=verification_method,
                                      status=status, extra=extra_doc)
        db_session.add(request)
        db_session.commit()

        return str(request_id) 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:27,代码来源:verification_request.py

示例3: create_user

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def create_user(**data):
    """Creates user with encrypted password"""
    if 'username' not in data or 'password' not in data:
        raise ValueError('username and password are required.')

    # Hash the user password
    data['password'] = generate_password_hash(
        data.pop('password'),
        method='pbkdf2:sha256'
    )

    # Here you insert the `data` in your users database
    # for this simple example we are recording in a json file
    db_users = json.load(open('users.json'))
    # add the new created user to json
    db_users[data['username']] = data
    # commit changes to database
    json.dump(db_users, open('users.json', 'w'))
    return data


# [--- Flask Factories  ---] 
开发者ID:flask-extensions,项目名称:flask_simplelogin,代码行数:24,代码来源:manage.py

示例4: reset_token

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for("main.home"))
    user = User.verify_reset_token(token)
    if user is None:
        flash("That is an invalid or expired token", "warning")
        return redirect(url_for("users.reset_request"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hash = generate_password_hash(form.password.data)
        user.password = hash
        db.session.commit()
        flash("Your password has been updated! You are now able to log in",
              "success")
        return redirect(url_for("users.login"))
    return render_template("reset_token.html",
                           title="Reset Password",
                           form=form) 
开发者ID:pxsocs,项目名称:thewarden,代码行数:20,代码来源:routes.py

示例5: user_create

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def user_create():
    """
    Create users.
    :return:
    """
    form = UserForm()

    if form.validate_on_submit():
        user = User()
        user.name = form.name.data
        user.hash_pass = generate_password_hash(form.password.data)
        user.role = form.role.data
        user.email = form.email.data
        db.session.add(user)
        db.session.commit()

        return redirect(url_for('.user'))

    return render_template('admin/user_create.html', form=form) 
开发者ID:Tianny,项目名称:incepiton-mysql,代码行数:21,代码来源:views.py

示例6: register

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        user = User()
        user.name = form.username.data
        user.hash_pass = generate_password_hash(form.password.data)
        user.email = form.email.data

        # Register user's role is dev, by default.
        user.role = 'dev'

        db.session.add(user)
        db.session.commit()

        flash('You have registered successfully. Please login! ', category='success')

        return redirect(url_for('auth.login'))

    return render_template('auth/register.html', form=form) 
开发者ID:Tianny,项目名称:incepiton-mysql,代码行数:21,代码来源:views.py

示例7: register

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def register():
    """Render the register page."""
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        c = mongo.db[app.config['USERS_COLLECTION']]
        user = {
            "username": form.username.data,
            "email": form.email.data,
            "first_name": form.first_name.data,
            "last_name": form.last_name.data,
            "password": generate_password_hash(form.password.data),
            "groups": [],
            "first_active": now_time(),
            "last_active": now_time()
        }
        logger.debug("User: %s" % user)
        user_count = c.count(dict())
        if user_count == 0:  # Make the first user an administrator
            user['groups'] = ['admin']
        _id = c.insert(user)
        next = request.args.get('next')
        return redirect(next or url_for('core.login'))
    errors = ','.join([value[0] for value in form.errors.values()])
    return render_template('register.html', message=errors) 
开发者ID:9b,项目名称:chirp,代码行数:26,代码来源:auth.py

示例8: create_user

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def create_user(name, email, groups, default_sharing, permissions, password=None):
    user = User.get(email=email.lower())

    if user:
        print "/!\ User with this email address already exists."
    else:
        user = User({
            'name': name,
            'email': email.lower(),
            'groups': groups,
            'default_sharing': default_sharing,
            'permissions': permissions,
            'enabled': True
        })
        if password:
            user['pwd_hash'] = generate_password_hash(password)
        user.save()
        print "[+] User created."

        user.generate_avatar()
        print "[+] Downloaded avatar."

    return user 
开发者ID:certsocietegenerale,项目名称:fame,代码行数:25,代码来源:user_management.py

示例9: setup

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def setup():
    """
    Called on a new install to setup an admin account
    """
    form = SetupForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        password = form.password.data
        hashed_password = generate_password_hash(password)

        # Create the account
        db = DB()
        resp = db.create(project_name, password, hashed_password, admin=True)
        if resp['status']:
            flash(u'Project successfully created!')
            return redirect(url_for('index'))
        else:
            flash(resp['message'])

    return render_template('setup.html', form=form) 
开发者ID:bitslabsyr,项目名称:stack,代码行数:23,代码来源:views.py

示例10: create

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def create():
    """
    Page to create a new project account
    """
    form = CreateForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        email = form.email.data
        password = form.password.data
        hashed_password = generate_password_hash(password)
        description = form.description.data

        # Create the account
        db = DB()
        resp = db.create(project_name, password, hashed_password, description=description, email=email)
        if resp['status']:
            flash(u'Project successfully created!')
            return redirect(url_for('admin_home', admin_id=g.admin['project_id']))
        else:
            flash(resp['message'])

    return render_template('create.html', form=form) 
开发者ID:bitslabsyr,项目名称:stack,代码行数:25,代码来源:views.py

示例11: make_account

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def make_account(name='test', fullname='Test User',
                 email='test@example.com', twitter='testuser',
                 admin=False, password='password'):
    from spendb.model.account import Account

    # First see if the account already exists and if so, return it
    account = Account.by_name(name)
    if account:
        return account

    # Account didn't exist so we create it and return it
    account = Account()
    account.name = name
    account.fullname = fullname
    account.email = email
    account.twitter_handle = twitter
    account.admin = admin
    account.password = generate_password_hash(password)
    db.session.add(account)
    db.session.commit()
    return account 
开发者ID:openspending,项目名称:spendb,代码行数:23,代码来源:helpers.py

示例12: avatar

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def avatar(self, user_id):
        random = generate_password_hash(str(user_id))
        fname = random[-10:] + '.jpg'
        current_app.logger.info(fname)

        f = request.files['avatar']
        # todo rename to uid relation
        # fname = secure_filename(f.filename)
        # TODO try
        ret = f.save(os.path.join(current_app.config['UPLOAD_AVATAR'], fname))
        user = UserModel.query.get(user_id)
        user.avatar = fname
        user.save()
        return self.render_json(data={
            'avatar': UserModel.avatar_url(user.avatar),
        }) 
开发者ID:meolu,项目名称:walle-web,代码行数:18,代码来源:user.py

示例13: __create

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def __create(self, args):
        result = {"status": "success", "msg": "创建用户成功"}
        user_path = self.app.config["AUTO_HOME"] + "/users/%s" % (args["username"])
        if not exists_path(user_path):
            mk_dirs(user_path)

            make_nod(user_path + "/config.json")

            user = {"fullname": args["fullname"],
                    "email": args["email"],
                    "passwordHash": generate_password_hash(args["password"]),
                    "data": []}
            json.dump(user, codecs.open(user_path + '/config.json', 'w', 'utf-8'))
        else:
            result["status"] = "fail"
            result["msg"] = "用户名称重复,创建失败"

        return result 
开发者ID:small99,项目名称:AutoLink,代码行数:20,代码来源:user.py

示例14: set_password

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def set_password(self, password):
        self.password_hash = generate_password_hash(password) 
开发者ID:PacktPublishing,项目名称:Mastering-Python-Networking-Second-Edition,代码行数:4,代码来源:chapter9_9.py

示例15: set_password

# 需要导入模块: from werkzeug import security [as 别名]
# 或者: from werkzeug.security import generate_password_hash [as 别名]
def set_password(self, password):
        """Create hashed password."""
        self.password = generate_password_hash(password, method='sha256') 
开发者ID:hackersandslackers,项目名称:flask-session-tutorial,代码行数:5,代码来源:models.py


注:本文中的werkzeug.security.generate_password_hash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。