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


Python User.password_hash方法代码示例

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


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

示例1: _create_fixture_users

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import password_hash [as 别名]
    def _create_fixture_users(self, config):
        ''' Create user fixtures. '''

        session = app.database.get_session(self._db)
        hash_algorithm = config.get('password_hash', 'algorithm')

        try:
            hash_rounds = int(config.get('password_hash', 'rounds'))
        except:
            raise ValueError('Configuration value password_hash.rounds must' \
                             ' be an integer: %s' % rounds)

        admin = User('admin')
        admin.agency = 'QuickPin'
        admin.name = 'Administrator'
        admin.is_admin = True
        admin.password_hash = model.user.hash_password(
            'MemexPass1',
            hash_algorithm,
            hash_rounds
        )
        session.add(admin)
        session.commit()
开发者ID:pombredanne,项目名称:quickpin,代码行数:25,代码来源:database.py

示例2: post

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import password_hash [as 别名]
    def post(self):
        '''
        Create a new application user.

        **Example Request**

        .. sourcecode:: json

            {
                "email": "[email protected]",
                "password": "superSECRET123"
            }

        **Example Response**

        .. sourcecode:: json

            {
                "agency": null,
                "created": "2015-05-05T14:30:09.676268",
                "email": "[email protected]",
                "id": 2029,
                "is_admin": false,
                "location": null,
                "modified": "2015-05-05T14:30:09.676294",
                "name": null,
                "phone": null,
                "thumb": null,
                "url": "https://quickpin/api/user/2029"
            }

        :<header Content-Type: application/json
        :<header X-Auth: the client's auth token
        :>json str email: e-mail address
        :>json str password: new password, must be >=8 characters, mixed case,

        :>header Content-Type: application/json
        :>json str agency: the name of the organization/agency that this person
            is affiliated with (default: null)
        :>json str created: record creation timestamp in ISO-8601 format
        :>json str email: e-mail address
        :>json bool is_admin: true if this user has admin privileges, false
            otherwise
        :>json str location: location name, e.g. city or state (default: null)
        :>json str modified: record modification timestamp in ISO-8601 format
        :>json str name: user's full name, optionally including title or other
            salutation information (default: null)
        :>json str phone: phone number
        :>json str phone_e164: phone number in E.164 format
        :>json str thumb: PNG thumbnail for this user, base64 encoded
        :>json str url: url to view data about this user

        :status 200: ok
        :status 400: invalid request body
        :status 401: authentication required
        :status 403: not authorized to create accounts
        :status 409: e-mail address already in use
        '''

        request_json = request.get_json()

        if 'email' not in request_json or '@' not in request_json['email']:
            raise BadRequest('Invalid or missing email.')

        user = User(request_json['email'].strip())

        if 'password' not in request_json:
            raise BadRequest('Password is required')

        password = request_json['password'].strip()

        if not valid_password(password):
            raise BadRequest('Password does not meet complexity requirements.')

        user.password_hash = hash_password(
            password,
            g.config.get('password_hash', 'algorithm'),
            int(g.config.get('password_hash', 'rounds'))
        )

        try:
            g.db.add(user)
            g.db.commit()
        except IntegrityError:
            raise Conflict('This e-mail address is already in use.')

        g.db.expire(user)

        return jsonify(**self._user_dict(user))
开发者ID:pombredanne,项目名称:quickpin,代码行数:91,代码来源:user.py


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