• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.hash_password函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.hash_password函数的典型用法代码示例。如果您正苦于以下问题:Python hash_password函数的具体用法?Python hash_password怎么用?Python hash_password使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: user_change_password

def user_change_password():
    user = session.get('user_info')
    o_password = request.values.get('old_password')
    n_password = request.values.get('new_password')
    n2_password = request.values.get('new2_password')
    session['action'] = 'password'

    if n_password != n2_password:
        session['error_message'] = '新密码输入不一致.'
        return redirect(url_for('user_profile'))

    if len(n_password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('user_profile'))

    user_key = '%s:%s' % ('user', user.get('username'))
    user_info = json.loads(r_session.get(user_key).decode('utf-8'))

    hashed_password = hash_password(o_password)

    if user_info.get('password') != hashed_password:
        session['error_message'] = '原密码错误'
        return redirect(url_for('user_profile'))

    user_info['password'] = hash_password(n_password)
    r_session.set(user_key, json.dumps(user_info))

    return redirect(url_for('user_profile'))
开发者ID:sykiewang,项目名称:crysadm,代码行数:28,代码来源:user.py


示例2: user_login

def user_login():
    username = request.values.get('username')
    password = request.values.get('password')

    hashed_password = hash_password(password)

    user_info = r_session.get('%s:%s' % ('user', username))
    if user_info is None:
        session['error_message'] = '用户不存在'
        return redirect(url_for('login'))

    user = json.loads(user_info.decode('utf-8'))

    if user.get('password') != hashed_password:
        session['error_message'] = '密码错误'
        return redirect(url_for('login'))

    if not user.get('active'):
        session['error_message'] = '您的账号已被禁用.'
        return redirect(url_for('login'))

    if user.get('log_as_body') is not None:
        if len(user.get('log_as_body')) > 0:
            r_session.set('%s:%s' % ('record', username), json.dumps(dict(diary=user.get('log_as_body')))) # 创建新通道,转移原本日记
            user['log_as_body'] = []

    user['login_time'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # 记录登陆时间
    r_session.set('%s:%s' % ('user', username), json.dumps(user)) # 修正数据

    if r_session.get('%s:%s' % ('record', username)) is None:
        r_session.set('%s:%s' % ('record', username), json.dumps(dict(diary=[]))) # 创建缺失的日记

    session['user_info'] = user

    return redirect(url_for('dashboard'))
开发者ID:JooPoo,项目名称:crysadm,代码行数:35,代码来源:user.py


示例3: update_profile

def update_profile(request):
    auth_user(request.cookies.get('auth'))
    if not g.user:
        result = {'status': 'error',
                  'error': 'Not authenticated.'
                  }
        return util.json_response(result)

    if request.POST.get('apisecret') != g.user["apisecret"]:
        result = {'status': 'error',
                  'error': 'Wrong form secret'
                  }
        return util.json_response(result)


    password = request.POST.get('password')    #optinal
    email = request.POST.get('email')
    about = request.POST.get('about')

    email, msg = util.check_string(email, maxlen=128)
    if email is None:
        result = {
            'status': 'error',
            'error': 'email ' + msg
            }
        return util.json_response(result)

    about, msg = util.check_string(about, maxlen=256)
    if about is None:
        result = {
            'status': 'error',
            'error': 'about ' + msg
            }
        return util.json_response(result)

    r = g.redis

    if password:
        password, msg = util.check_string(password, config.PasswordMinLength)
        if not password:
            result = {
                'status': 'error',
                'error': 'password ' + msg
                }
            return util.json_response(result)

        r.hset("user:" + g.user['id'], "password",
               util.hash_password(password, g.user['salt']))

    r.hmset("user:" + g.user['id'], {
            "about": about.rstrip(),
            "email": email
            })
    return util.json_response({'status': "ok"})
开发者ID:pid-t,项目名称:lusernews,代码行数:54,代码来源:api.py


示例4: create_user

def create_user(form):
    """
    Create a new user given registration form
    """
    hashed, salt = hash_password(form["password"])
    new_user = User(email=form["email"], hashed_password=hashed, salt=salt)
    # give user access to public data
    authorize_public_data(new_user)
    db.session.add(new_user)
    db.session.commit()
    return new_user
开发者ID:chaiery,项目名称:FHIR-Genomics-2,代码行数:11,代码来源:ui.py


示例5: admin_change_password

def admin_change_password(username):
    n_password = request.values.get('new_password')

    if len(n_password) < 8:
        session['error_message'] = '密码必须8位以上.'
        return redirect(url_for(endpoint='admin_user_management', username=username))

    user_key = '%s:%s' % ('user', username)
    user_info = json.loads(r_session.get(user_key).decode('utf-8'))

    user_info['password'] = hash_password(n_password)
    r_session.set(user_key, json.dumps(user_info))

    return redirect(url_for(endpoint='admin_user_management', username=username))
开发者ID:HuiMi24,项目名称:crysadm,代码行数:14,代码来源:admin.py


示例6: user_register

def user_register():
    invitation_code = request.values.get('invitation_code')

    if not r_session.sismember('invitation_codes', invitation_code) and \
    not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if username == '':
        session['error_message'] = '用户名不能为空.'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该用户名已存在.'
        return redirect(url_for('register'))

    r = r"(^[a-zA-Z]+[a-zA-Z0-9_-]+$)"
    if re.match(r, username) is None:
        session['error_message'] = '用户名由字母开头数字和下划线组成.'
        return redirect(url_for('register'))

    if len(username) < 6 or len(username) > 20:
        session['error_message'] = '用户名长度在6~20个字符之间.'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '两次输入的密码不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '输入的密码必须8位数以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
开发者ID:caiyy,项目名称:crysadm,代码行数:48,代码来源:user.py


示例7: install

def install():
    import random, uuid
    from util import hash_password

    if r_session.scard('users') == 0:
        _chars = "0123456789ABCDEF"
        username = ''.join(random.sample(_chars, 6))
        password = ''.join(random.sample(_chars, 6))

        user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                    active=True, is_admin=True, max_account_no=2,
                    created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        r_session.set('%s:%s' % ('user', username), json.dumps(user))
        r_session.sadd('users', username)
        return 'username:%s,password:%s' % (username, password)

    return redirect(url_for('login'))
开发者ID:burt1012,项目名称:crysadm,代码行数:17,代码来源:web_common.py


示例8: create

 def create(self):
     self.created_at = time.time()
     if not self.validate():
         return
     if User.find_first('where email = ?', self.email):
         self.errors = {'email': u'此email已被占用'}
         return
     if User.find_first('where name = ?', self.name):
         self.errors = {'name': u'此用戶名已被注冊'}
         return
     if not self.password_confirm:
         self.errors = {'password_confirm': u'确认密码不能为空'}
         return
     if self.password != self.password_confirm:
         self.errors = {'password': u'兩次密碼輸入不一致'}
         return
     self.password = hash_password(self.password)
     self.insert()
     return self.id
开发者ID:hazelnutssoft,项目名称:cam_survilliance_server,代码行数:19,代码来源:user.py


示例9: user_register

def user_register():
    invitation_code = request.values.get("invitation_code")
    username = request.values.get("username")
    password = request.values.get("password")
    re_password = request.values.get("re_password")

    if not r_session.sismember("invitation_codes", invitation_code) and not r_session.sismember(
        "public_invitation_codes", invitation_code
    ):
        session["error_message"] = "无效的邀请码。"
        return redirect(url_for("register"))

    if username == "":
        session["error_message"] = "账号名不能为空。"
        return redirect(url_for("register"))

    if r_session.get("%s:%s" % ("user", username)) is not None:
        session["error_message"] = "该账号名已存在。"
        return redirect(url_for("register"))

    if password != re_password:
        session["error_message"] = "新密码输入不一致."
        return redirect(url_for("register"))

    if len(password) < 8:
        session["error_message"] = "密码必须8位及以上."
        return redirect(url_for("register"))

    r_session.srem("invitation_codes", invitation_code)
    r_session.srem("public_invitation_codes", invitation_code)

    user = dict(
        username=username,
        password=hash_password(password),
        id=str(uuid.uuid1()),
        active=True,
        is_admin=False,
        max_account_no=2,
        created_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    )
    r_session.set("%s:%s" % ("user", username), json.dumps(user))
    r_session.sadd("users", username)
    return redirect(url_for("login"))
开发者ID:nyko0311,项目名称:crysadm,代码行数:43,代码来源:user.py


示例10: change_password

    def change_password(self, origin_password, password, password_confirm):
        if not origin_password:
            self.errors['origin_password'] = u'当前密码不能为空'

        if not password:
            self.errors['password'] = u'密码不能为空'

        if not password_confirm:
            self.errors['password_confirm'] = u'确认密码不能为空'

        if password!= password_confirm:
            self.errors['password_confirm'] = u'两次密码不一致'

        if self.errors:
            return False

        self.password = hash_password(self.password)

        self.update()
开发者ID:hazelnutssoft,项目名称:cam_survilliance_server,代码行数:19,代码来源:user.py


示例11: register_user

def register_user():
    email = request.values.get('username')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')
    r = r"(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    if re.match(r, email) is None:
        session['error_message'] = '邮箱地址格式不正确.'
        return redirect(url_for('add_user'))
    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('add_user'))
    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('add_user'))
    if password != re_password:
        session['error_message'] = '密码输入不一致.'
        return redirect(url_for('add_user'))
    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('add_user'))
    if r_session.sismember('email', email):
        session['error_message'] = '该邮件地址已被注册.'
        return redirect(url_for('add_user'))
    config_key = '%s:%s' % ('user', 'system')
    config_info = json.loads(r_session.get(config_key).decode('utf-8'))
    if 'trial_period' not in config_info.keys():
        config_info['trial_period'] = 14
    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=1, email=email,total_account_point=config_info['trial_period'],
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    days=int(user.get('total_account_point')/user.get('max_account_no'))
    if days<36500:
        user['expire_date'] = (datetime.now() + timedelta(days=days)).strftime('%Y-%m-%d')
    else:
        user['expire_date'] = (datetime.now() + timedelta(days=36500)).strftime('%Y-%m-%d')
    r_session.set('%s:%s' % ('user', user.get('username')), json.dumps(user))
    r_session.set('%s:%s' % ('record', user.get('username')), json.dumps(dict(diary=[])))
    r_session.sadd('users', user.get('username'))
    r_session.sadd('email', user.get('email'))
    session['info_message'] = '注册成功'
    return redirect(url_for('admin_user'))
开发者ID:fengyuclub,项目名称:crysadm,代码行数:42,代码来源:admin.py


示例12: user_register

def user_register():
    invitation_code = request.values.get('invitation_code')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    if not r_session.sismember('invitation_codes', invitation_code) and \
            not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '新密码输入不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    r_session.set('%s:%s' % ('user', username), json.dumps(user))
    r_session.set('%s:%s' % ('record', username), json.dumps(dict(diary=[])))
    r_session.sadd('users', username)

    session['info_message'] = '恭喜你,注册成功.'
    return redirect(url_for('register'))
开发者ID:care4rei,项目名称:crysadm,代码行数:39,代码来源:user.py


示例13: user_login

def user_login():
    try:
        username = request.values.get('username')
        password = request.values.get('password')
        hashed_password = hash_password(password)
        user_info = r_session.get('%s:%s' % ('user', username))
        if user_info is None:
            session['error_message'] = '用户不存在'
            return redirect(url_for('login'))

        user = json.loads(user_info.decode('utf-8'))
        if user.get('password') != hashed_password:
            session['error_message'] = '密码错误'
            return redirect(url_for('login'))
        if not user.get('active'):
            session['error_message'] = '您的账号已被禁用.'
            return redirect(url_for('login'))
        session['user_info'] = user

        return redirect(url_for('dashboard'))
    except Exception as e:
        return  
开发者ID:crysadm,项目名称:crysadm,代码行数:22,代码来源:user.py


示例14: create_user

def create_user(username, password, userip):
    r = g.redis
    username = username.lower()
    if r.exists("username.to.id:" + username):
        return None, "Username exists, please try a different one."

    if not util.lock('create_user.' + username):
        return None, "Please wait some time before creating a new user."

    user_id = r.incr("users.count")
    auth_token = util.get_rand()
    salt = util.get_rand()
    now = int(time.time())

    pl = r.pipeline()
    pl.hmset("user:%s" % user_id, {
            "id": user_id,
            "username": username,
            "salt": salt,
            "password": util.hash_password(password, salt),
            "ctime": now,
            "karma": config.UserInitialKarma,
            "about": "",
            "email": "",
            "auth": auth_token,
            "apisecret": util.get_rand(),
            "flags": "",
            "karma_incr_time": now,
            "replies": 0,
            })

    pl.set("username.to.id:" + username, user_id)
    pl.set("auth:" + auth_token, user_id)
    pl.execute()

    util.unlock('create_user.' + username)

    return auth_token, None
开发者ID:argolab,项目名称:lusernews,代码行数:38,代码来源:user.py


示例15: update_profile

def update_profile(request):
    auth_user(request.cookies.get("auth"))
    if not g.user:
        result = {"status": "error", "error": "Not authenticated."}
        return util.json_response(result)

    if request.POST.get("apisecret") != g.user["apisecret"]:
        result = {"status": "error", "error": "Wrong form secret"}
        return util.json_response(result)

    password = request.POST.get("password")  # optinal
    email = request.POST.get("email")
    about = request.POST.get("about")

    email, msg = util.check_string(email, maxlen=128)
    if email is None:
        result = {"status": "error", "error": "email " + msg}
        return util.json_response(result)

    about, msg = util.check_string(about, maxlen=256)
    if about is None:
        result = {"status": "error", "error": "about " + msg}
        return util.json_response(result)

    r = g.redis

    if password:
        password, msg = util.check_string(password, config.PasswordMinLength)
        if not password:
            result = {"status": "error", "error": "password " + msg}
            return util.json_response(result)

        salt = g.user.get("salt", util.get_rand())
        r.hmset("user:" + g.user["id"], {"password": util.hash_password(password, salt), "salt": salt})

    r.hmset("user:" + g.user["id"], {"about": about.rstrip(), "email": email})
    return util.json_response({"status": "ok"})
开发者ID:spearous,项目名称:lusernews,代码行数:37,代码来源:api.py


示例16: user_login

def user_login():
    username = request.values.get("username")
    password = request.values.get("password")

    hashed_password = hash_password(password)

    user_info = r_session.get("%s:%s" % ("user", username))
    if user_info is None:
        session["error_message"] = "用户不存在"
        return redirect(url_for("login"))

    user = json.loads(user_info.decode("utf-8"))

    if user.get("password") != hashed_password:
        session["error_message"] = "密码错误"
        return redirect(url_for("login"))

    if not user.get("active"):
        session["error_message"] = "您的账号已被禁用."
        return redirect(url_for("login"))

    session["user_info"] = user

    return redirect(url_for("dashboard"))
开发者ID:nyko0311,项目名称:crysadm,代码行数:24,代码来源:user.py


示例17: user_register

def user_register():
    email = request.values.get('username')
    invitation_code = request.values.get('invitation_code')
    username = request.values.get('username')
    password = request.values.get('password')
    re_password = request.values.get('re_password')

    r = r"(^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    if re.match(r, email) is None:
        session['error_message'] = '邮箱地址格式不正确.'
        return redirect(url_for('register'))

    if username == '':
        session['error_message'] = '账号名不能为空。'
        return redirect(url_for('register'))

    if r_session.get('%s:%s' % ('user', username)) is not None:
        session['error_message'] = '该账号名已存在。'
        return redirect(url_for('register'))

    if password != re_password:
        session['error_message'] = '新密码输入不一致.'
        return redirect(url_for('register'))

    if len(password) < 8:
        session['error_message'] = '密码必须8位及以上.'
        return redirect(url_for('register'))

    if r_session.sismember('email', email):
        session['error_message'] = '该邮件地址已被注册.'
        return redirect(url_for('register'))

    if not r_session.sismember('invitation_codes', invitation_code) and \
            not r_session.sismember('public_invitation_codes', invitation_code):
        session['error_message'] = '无效的邀请码。'
        return redirect(url_for('register'))

    email_code = r_session.get('emailcode:%s' % email)
    if email_code is not None:
        code_time = json.loads(email_code.decode('utf-8'))
        if datetime.strptime(code_time, '%Y-%m-%d %H:%M:%S') + timedelta(minutes=5) > datetime.now():
            session['error_message'] = '发送邮件过于频繁 请稍候再试.'
            return redirect(url_for('register'))

    _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    key = ''.join(random.sample(_chars, 36))
    user = dict(username=username, password=hash_password(password), id=str(uuid.uuid1()),
                active=True, is_admin=False, max_account_no=20, email=email,
                created_time=datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

    r_session.setex('emailcode:%s' % email, json.dumps(user.get('created_time')), 60*5)
    r_session.setex('activecode:%s' % key, json.dumps(user), 60*30)

    bytesString = key.encode('utf-8')
    encodestr = base64.b64encode(bytesString)

    if user_email(email, encodestr.decode('utf-8')) != True:
        session['error_message'] = '激活帐户邮件发送失败 邮箱不存在.'
        return redirect(url_for('register'))

    r_session.srem('invitation_codes', invitation_code)
    r_session.srem('public_invitation_codes', invitation_code)

    session['info_message'] = '激活帐户邮件已发送到您的邮箱.'
    return redirect(url_for('register'))
开发者ID:8375618,项目名称:crysadm,代码行数:65,代码来源:user.py


示例18: check_password

 def check_password(self, password):
     hashed, _ = hash_password(password, self.salt)
     return hashed == self.hashed_password
开发者ID:bcl-lab,项目名称:FHIR-Genomics_v2,代码行数:3,代码来源:models.py


示例19: user_login

def user_login(username, password):
    u = user.User.find_first('where name = ? and password = ?', username, hash_password(password))
    if u:
        return u.id
    else:
        return None
开发者ID:hazelnutssoft,项目名称:cam_survilliance_server,代码行数:6,代码来源:task.py


示例20: check_user_credentials

def check_user_credentials(username, password):
    user = get_user_by_name(username)
    if not (user and user.has_key('password') and \
                user['password'] ==  util.hash_password(password, user['salt'])):
        return None, None
    return user['auth'], user['apisecret']
开发者ID:argolab,项目名称:lusernews,代码行数:6,代码来源:user.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.hashable函数代码示例发布时间:2022-05-26
下一篇:
Python util.grid_equal函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap