本文整理匯總了Python中database.User.password方法的典型用法代碼示例。如果您正苦於以下問題:Python User.password方法的具體用法?Python User.password怎麽用?Python User.password使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類database.User
的用法示例。
在下文中一共展示了User.password方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_user
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import password [as 別名]
def create_user(Session,username,password,public_key,creator):
s=Session
user=get_user(s,username)
if user is None:
if creator:
cid=creator.id
else:
cid=None
u=User(name=username,password=genpw(password),creator=cid,public_key=public_key)
s.add(u)
s.commit()
return True
else:
u=user
if not creator: return False
if u.id==creator.id or creator.name=='admin':
if not password is None:
if password=='':
u.password=''
else:
u.password=genpw(password)
if not public_key is None:
u.public_key=public_key
s.merge(u)
s.commit()
return True
return False
示例2: register_view
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import password [as 別名]
def register_view(self):
form = RegistrationForm(request.form)
if helpers.validate_form_on_submit(form):
user = User()
form.populate_obj(user)
# we hash the users password to avoid saving it as plaintext in the db,
# remove to use plain text:
user.password = generate_password_hash(form.password.data)
db.session.add(user)
db.session.commit()
login.login_user(user)
return redirect(url_for('.index'))
link = '<p>Already have an account? <a href="' + url_for('.login_view') + '">Click here to log in.</a></p>'
self._template_args['form'] = form
self._template_args['link'] = link
return super(MyAdminIndexView, self).index()
示例3: register_view
# 需要導入模塊: from database import User [as 別名]
# 或者: from database.User import password [as 別名]
def register_view():
form = RegistrationForm(request.form)
if form.validate_on_submit():
user = User()
form.populate_obj(user)
user.salt = str(time.time())
hash_password = hashlib.sha512()
hash_password.update(user.salt + user.password)
user.password = hash_password.hexdigest()
db.session.add(user)
db.session.commit()
login.login_user(user)
flash('You were registered', 'info')
return redirect(url_for('show_challenges'))
return render_template('form.html', form=form)