def check_password(self, password):
return check_password_hash(self.password, password)
python类check_password_hash()的实例源码
def authenticate(self, password):
checked = check_password_hash(self.password, password)
self._authenticated = checked
return self._authenticated
def check_password(self, password):
"""Check passwords. If passwords match it returns true, else false."""
if self.password is None:
return False
return check_password_hash(self.password, password)
def login():
form = LoginForm()
# Shows login form
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user:
if user.confirmed_email:
if check_password_hash(user.password, form.password.data):
login_user(
user,
remember=form.remember.data
)
admin = User.query.filter_by(
username=str(user.username)
).first()
admin.is_active = True
db.session.commit()
session['logged'] = 'YES'
if current_user:
hriks(
'SUCCESS! Welcome, you are logged in %s' % (
user.username
)
)
return redirect(url_for('index'))
return redirect(url_for('login'))
hriks(
'WARNING! Invalid Combination,\
Please check username and password'
)
return render_template('login.html', form=form)
return render_template('login.html', form=form)
# This is Signup form route, it accepts both GET and POST
# request. It renders signup form page using GET and submit
# form using POST request.
# This method also send confirm mail to user
# clicking on which user needs to verify his identity
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def check_password(self, password):
return check_password_hash(self.password, password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
# Gravatar??????
def login_view(self):
form = LoginForm(request.form)
if helpers.validate_form_on_submit(form):
user = form.get_user()
if user is None:
flash('???????')
elif not check_password_hash(user.password, form.password.data):
flash('?????')
elif user is not None and check_password_hash(user.password, form.password.data):
login_user(user)
if current_user.is_authenticated:
return redirect(url_for('admin.index'))
self._template_args['form'] = form
#self._template_args['link'] = link
return super(MyAdminIndexView, self).index()
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def login():
if 'username' in session:
return jsonify(status_error_already_logged_in)
else:
if request.method == 'POST':
if Users.query.filter_by(USERNAME=request.form['username']).first() is None:
return jsonify(status_error_wrong_username_or_password)
else:
user = Users.query.filter_by(USERNAME=request.form['username']).first()
if check_password_hash(user.PASSWORD, request.form['password']) is False:
return jsonify(status_error_wrong_username_or_password)
else:
session['username'] = request.form['username']
return jsonify(status_ok_login_successfully)
return render_template("user/login.html")
def user_password_change():
if 'username' in session:
if session['username'] != "admin":
if request.method == "POST":
if Users.query.filter_by(USERNAME=session['username']).first() is None:
return jsonify(status_error_does_not_exist_username)
else:
user = Users.query.filter_by(USERNAME=session['username']).first()
if check_password_hash(user.PASSWORD, request.form['password']) is False:
return jsonify(status_error_wrong_username_or_password)
else:
user.PASSWORD = generate_password_hash(request.form['password_new'])
try:
db.session.add(user)
db.session.commit()
except:
return jsonify(status_error_unknown_error)
else:
return jsonify(status_ok_edit_successfully)
else:
return render_template('user/user_change_password.html')
else:
if request.method == "POST":
if Users.query.filter_by(ID_USER=request.form['id_user']).first() is None:
return jsonify(status_error_does_not_exist_username)
else:
user = Users.query.filter_by(ID_USER=request.form['id_user']).first()
user.PASSWORD = generate_password_hash(request.form['password_new'])
try:
db.session.add(user)
db.session.commit()
except:
return jsonify(status_error_unknown_error)
else:
return jsonify(status_ok_edit_successfully)
else:
return render_template('user/user_change_password_admin.html')
else:
return jsonify(status_error_permission_denied)
def verify_password(self, password):
"""
????
:param password: ?????
:return: ???? True,???? False
"""
return check_password_hash(self.password, password)
##
# ??????
##
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
chapter9_9.py 文件源码
项目:Mastering-Python-Networking
作者: PacktPublishing
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def verify_password(self,password) :
return check_password_hash(self.password_hash,password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
def _change_password():
current = request.form.get('current_password', '')
new = request.form.get('new_password', '')
confirm = request.form.get('confirm_password', '')
if not check_password_hash(current_user['pwd_hash'], current):
flash('Current password is invalid', 'danger')
elif valid_new_password(new, confirm):
change_password(current_user, new)
flash('Password was successfully changed.', 'success')
return redirect(request.referrer)
def authenticate(email, password):
user = User.get(email=email.lower())
if user_if_enabled(user):
if 'pwd_hash' in user:
if check_password_hash(user['pwd_hash'], password):
if 'auth_token' not in user:
user.update_value('auth_token', auth_token(user))
login_user(user)
return user
return None
def verify_password(self, password):
return check_password_hash(self.password_hash, password)