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

Python util.password_hash函数代码示例

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

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



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

示例1: profile_password

def profile_password():
  if not config.CONFIG_DB.has_email_authentication:
    flask.abort(418)
  user_db = auth.current_user_db()
  form = ProfilePasswordForm(obj=user_db)

  if form.validate_on_submit():
    errors = False
    old_password = form.old_password.data
    new_password = form.new_password.data
    if new_password or old_password:
      if user_db.password_hash:
        if util.password_hash(user_db, old_password) != user_db.password_hash:
          form.old_password.errors.append('Invalid current password')
          errors = True
      if not errors and old_password and not new_password:
        form.new_password.errors.append('This field is required.')
        errors = True

      if not (form.errors or errors):
        user_db.password_hash = util.password_hash(user_db, new_password)
        flask.flash('Your password has been changed.', category='success')

    if not (form.errors or errors):
      user_db.put()
      return flask.redirect(flask.url_for('profile'))

  return flask.render_template(
      'profile/profile_password.html',
      title=user_db.name,
      html_class='profile-password',
      form=form,
      user_db=user_db,
    )
开发者ID:ColdSauce,项目名称:FIRSTMastery,代码行数:34,代码来源:profile.py


示例2: change_password

	def change_password(self, username, old_password, new_password1, new_password2):
		# validate passwords:
		if not validate_password(new_password1):
			raise exception.InvalidParameterException("new_password1")

		if new_password1 != new_password2:
			raise exception.InvalidParameterException("new_password2")

		# change password:
		with self.__create_db_connection__() as conn:
			with conn.enter_scope() as scope:
				self.__test_active_user__(scope, username)

				if self.__validate_password__(scope, username, old_password):
					# change password:
					salt = util.generate_junk(config.PASSWORD_SALT_LENGTH, secure=True)
					hash = util.password_hash(new_password1, salt)

					self.__user_db.update_user_password(scope, username, hash, salt)

					# generate mail:
					user = self.__user_db.get_user(scope, username)

					tpl = template.PasswordChangedMail(self.__get_language__(user))
					tpl.bind(username=username)
					subject, body = tpl.render()

					self.__mail_db.push_user_mail(scope, subject, body, user["id"])

					mailer.ping(config.MAILER_HOST, config.MAILER_PORT)

					scope.complete()

				else:
					raise exception.WrongPasswordException()
开发者ID:20centaurifux,项目名称:meat-a,代码行数:35,代码来源:app.py


示例3: user_reset

def user_reset(token=None):
  user_db = model.User.get_by('token', token)
  if not user_db:
    flask.flash(__('That link is either invalid or expired.'), category='danger')
    return flask.redirect(flask.url_for('welcome'))

  if auth.is_logged_in():
    login.logout_user()
    return flask.redirect(flask.request.path)

  form = UserResetForm()
  if form.validate_on_submit():
    user_db.password_hash = util.password_hash(user_db, form.new_password.data)
    user_db.token = util.uuid()
    user_db.verified = True
    user_db.put()
    flask.flash(__('Your password was changed succesfully.'), category='success')
    return auth.signin_user_db(user_db)

  return flask.render_template(
      'user/user_reset.html',
      title='Reset Password',
      html_class='user-reset',
      form=form,
      user_db=user_db,
    )
开发者ID:mdxs,项目名称:gae-init-babel,代码行数:26,代码来源:user.py


示例4: activate_user

	def activate_user(self, id, code):
		with self.__create_db_connection__() as conn:
			with conn.enter_scope() as scope:
				# find request id & test code:
				if not self.__user_db.user_request_id_exists(scope, id):
					raise exception.NotFoundException("Request not found.")

				request = self.__user_db.get_user_request(scope, id)

				if request["request_code"] != code:
					raise exception.InvalidRequestCodeException()

				# activate user account:
				password = util.generate_junk(config.DEFAULT_PASSWORD_LENGTH, secure=True)
				salt = util.generate_junk(config.PASSWORD_SALT_LENGTH, secure=True)

				user_id = self.__user_db.activate_user(scope, id, code, util.password_hash(password, salt), salt)

				# generate mail:
				tpl = template.AccountActivatedMail(config.DEFAULT_LANGUAGE)
				tpl.bind(username=request["username"], password=password)
				subject, body = tpl.render()

				self.__mail_db.push_user_mail(scope, subject, body, user_id)

				mailer.ping(config.MAILER_HOST, config.MAILER_PORT)

				scope.complete()

				return request["username"], request["email"], password
开发者ID:20centaurifux,项目名称:meat-a,代码行数:30,代码来源:app.py


示例5: user_activate

def user_activate(token):
  if auth.is_logged_in():
    login.logout_user()
    return flask.redirect(flask.request.path)

  user_db = model.User.get_by('token', token)
  if not user_db:
    flask.flash(__('That link is either invalid or expired.'), category='danger')
    return flask.redirect(flask.url_for('welcome'))

  form = UserActivateForm(obj=user_db)
  if form.validate_on_submit():
    form.populate_obj(user_db)
    user_db.password_hash = util.password_hash(user_db, form.password.data)
    user_db.token = util.uuid()
    user_db.verified = True
    user_db.put()
    return auth.signin_user_db(user_db)

  return flask.render_template(
      'user/user_activate.html',
      title='Activate Account',
      html_class='user-activate',
      user_db=user_db,
      form=form,
    )
开发者ID:mdxs,项目名称:gae-init-babel,代码行数:26,代码来源:user.py


示例6: get_by_credentials

    def get_by_credentials(cls, email_or_username, password):
        """Gets user model instance by email or username with given password"""
        try:
            email_or_username == User.email
        except ValueError:
            cond = email_or_username == User.username
        else:
            cond = email_or_username == User.email
        user_db = User.query(cond).get()

        if user_db and user_db.password_hash == util.password_hash(password):
            return user_db
        return None
开发者ID:derasd,项目名称:woTravel,代码行数:13,代码来源:user.py


示例7: post

 def post(self, key):
     """Changes user's password"""
     parser = reqparse.RequestParser()
     parser.add_argument('currentPassword', type=UserValidator.create('password', required=False), dest='current_password')
     parser.add_argument('newPassword', type=UserValidator.create('password'), dest='new_password')
     args = parser.parse_args()
     # Users, who signed up via social networks have empty password_hash, so they have to be allowed
     # to change it as well
     if g.model_db.password_hash != '' and not g.model_db.has_password(args.current_password):
         raise ValueError('Given password is incorrect.')
     g.model_db.password_hash = util.password_hash(args.new_password)
     g.model_db.put()
     return make_empty_ok_response()
开发者ID:derasd,项目名称:woTravel,代码行数:13,代码来源:user_api.py


示例8: post

  def post(self):
    username = util.param('username') or util.param('email')
    password = util.param('password')
    if not username or not password:
      return flask.abort(400)

    if username.find('@') > 0:
      user_db = model.User.get_by('email', username.lower())
    else:
      user_db = model.User.get_by('username', username.lower())

    if user_db and user_db.password_hash == util.password_hash(user_db, password):
      auth.signin_user_db(user_db)
      return helpers.make_response(user_db, model.User.FIELDS)
    return flask.abort(401)
开发者ID:c0debrain,项目名称:gae-init,代码行数:15,代码来源:auth.py


示例9: get_user_db_from_email

def get_user_db_from_email(email, password):
  user_dbs, cursors = model.User.get_dbs(email=email, active=True, limit=2)
  if not user_dbs:
    return None
  if len(user_dbs) > 1:
    flask.flash('''We are sorry but it looks like there is a conflict with
        your account. Our support team is already informed and we will get
        back to you as soon as possible.''', category='danger')
    task.email_conflict_notification(email)
    return False

  user_db = user_dbs[0]
  if user_db.password_hash == util.password_hash(user_db, password):
    return user_db
  return None
开发者ID:pombredanne,项目名称:github-stats,代码行数:15,代码来源:auth.py


示例10: post

 def post(self):
     """Sets new password given by user if he provided valid token
     Notice ndb.toplevel decorator here, so we can perform asynchronous put
      and signing in in parallel
     """
     parser = reqparse.RequestParser()
     parser.add_argument('token', type=UserValidator.create('token'))
     parser.add_argument('newPassword', type=UserValidator.create('password'), dest='new_password')
     args = parser.parse_args()
     user_db = User.get_by('token', args.token)
     user_db.password_hash = util.password_hash(args.new_password)
     user_db.token = util.uuid()
     user_db.verified = True
     user_db.put_async()
     auth.signin_user_db(user_db)
     return user_db.to_dict(include=User.get_private_properties())
开发者ID:jacraven,项目名称:lsiapp,代码行数:16,代码来源:auth_api.py


示例11: reset_password

	def reset_password(self, id, code, new_password1, new_password2):
		# validate passwords:
		if not validate_password(new_password1):
			raise exception.InvalidParameterException("new_password1")

		if new_password1 != new_password2:
			raise exception.InvalidParameterException("new_password2")

		# reset password:
		with self.__create_db_connection__() as conn:
			with conn.enter_scope() as scope:
				# find request id & test code:
				if not self.__user_db.password_request_id_exists(scope, id):
					raise exception.NotFoundException("Request not found.")

				request = self.__user_db.get_password_request(scope, id)
				username = request["user"]["username"]

				self.__test_active_user__(scope, username)

				if request["request_code"] != code:
					raise exception.InvalidRequestCodeException()

				# change password:
				salt = util.generate_junk(config.PASSWORD_SALT_LENGTH, secure=True)

				hash = util.password_hash(new_password1, salt)
				self.__user_db.reset_password(scope, id, code, hash, salt)

				# generate mail:
				user = self.__user_db.get_user(scope, username)

				tpl = template.PasswordChangedMail(self.__get_language__(user))
				tpl.bind(username=username)
				subject, body = tpl.render()

				self.__mail_db.push_user_mail(scope, subject, body, user["id"])

				mailer.ping(config.MAILER_HOST, config.MAILER_PORT)

				scope.complete()

				return username, new_password1
开发者ID:20centaurifux,项目名称:meat-a,代码行数:43,代码来源:app.py


示例12: post

	def post(self):
		args = parser.parse({
			'username': wf.Str(missing=None),
			'email': wf.Str(missing=None),
			'password': wf.Str(missing=None),
		})
		handler = args['username'] or args['email']
		password = args['password']
		if not handler or not password:
			return flask.abort(400)

		user_db = model.User.get_by(
				'email' if '@' in handler else 'username', handler.lower()
		)

		if user_db and user_db.password_hash == util.password_hash(user_db, password):
			auth.signin_user_db(user_db)
			return helpers.make_response(user_db, model.User.FIELDS)
		return flask.abort(401)
开发者ID:stretchhog,项目名称:prfit,代码行数:19,代码来源:auth.py


示例13: create_user_db

def create_user_db(auth_id, name, username, email='', verified=False, password='', **props):
    """Saves new user into datastore"""
    if password:
        password = util.password_hash(password)

    email = email.lower()
    user_db = model.User(
        name=name,
        email=email,
        username=username,
        auth_ids=[auth_id] if auth_id else [],
        verified=verified,
        token=util.uuid(),
        password_hash=password,
        **props
    )
    user_db.put()
    task.new_user_notification(user_db)
    return user_db
开发者ID:Huijari,项目名称:gae_test,代码行数:19,代码来源:auth.py


示例14: user_activate

def user_activate(token):
    if auth.is_logged_in():
        login.logout_user()
        return flask.redirect(flask.request.path)

    user_db = models.User.get_by("token", token)
    if not user_db:
        flask.flash("That link is either invalid or expired.", category="danger")
        return flask.redirect(flask.url_for("welcome"))

    form = forms.UserActivateForm(obj=user_db)
    if form.validate_on_submit():
        form.populate_obj(user_db)
        user_db.password_hash = util.password_hash(user_db, form.password.data)
        user_db.token = util.uuid()
        user_db.verified = True
        user_db.put()
        return auth.signin_user_db(user_db)

    return flask.render_template(
        "user/user_activate.html", title="Activate Account", html_class="user-activate", user_db=user_db, form=form
    )
开发者ID:gmist,项目名称:1businka2,代码行数:22,代码来源:views.py


示例15: user_reset

def user_reset(token=None):
    user_db = models.User.get_by("token", token)
    if not user_db:
        flask.flash("That link is either invalid or expired.", category="danger")
        return flask.redirect(flask.url_for("welcome"))

    if auth.is_logged_in():
        login.logout_user()
        return flask.redirect(flask.request.path)

    form = forms.UserResetForm()
    if form.validate_on_submit():
        user_db.password_hash = util.password_hash(user_db, form.new_password.data)
        user_db.token = util.uuid()
        user_db.verified = True
        user_db.put()
        flask.flash("Your password was changed succesfully.", category="success")
        return auth.signin_user_db(user_db)

    return flask.render_template(
        "user/user_reset.html", title="Reset Password", html_class="user-reset", form=form, user_db=user_db
    )
开发者ID:gmist,项目名称:1businka2,代码行数:22,代码来源:views.py


示例16: __validate_password__

	def __validate_password__(self, scope, username, password):
		current_password, salt = self.__db.get_user_password(scope, username)

		return util.password_hash(password, salt) == current_password
开发者ID:20centaurifux,项目名称:meat-a,代码行数:4,代码来源:app.py


示例17: has_password

 def has_password(self, password):
     """Tests if user has given password"""
     return self.password_hash == util.password_hash(password)
开发者ID:derasd,项目名称:woTravel,代码行数:3,代码来源:user.py


示例18: create_admin

 def create_admin(cls):
     """Creates mock admin user"""
     cls(username='admin', password_hash=util.password_hash('123456'), admin=True, verified=True, active=True)
开发者ID:wodore,项目名称:wodore-ng,代码行数:3,代码来源:user_factory.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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