Код: Выделить всё
hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
Код: Выделить всё
if user and bcrypt.check_password_hash(user.password, password):
login_user(user)
Моя регистрация Код:
Код: Выделить всё
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
first_name = request.form.get("first_name")
last_name = request.form.get("last_name")
email = request.form.get("email")
password = request.form.get("password")
hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
user = User(first_name, last_name, email, hashed_password)
db.session.add(user)
db.session.commit()
return redirect(url_for('login'))
return render_template('register.html')
Код: Выделить всё
@app.route('/login', methods = ['GET', 'POST'])
def login():
if request.method == 'POST':
email=request.form.get("email")
password = request.form.get("password")
user = User.query.filter_by(email=email).first()
if user and bcrypt.check_password_hash(user.password, password):
login_user(user)
return redirect(url_for('dashboard'))
return render_template('login.html', error="Invalid email or password.")
return render_template('login.html')
Код: Выделить всё
from flask_bcrypt import Bcrypt
bcrypt = Bcrypt()
# Simulate password hashing
password = "test"
hashed = bcrypt.generate_password_hash(password).decode('utf-8')
print(f"Hashed password: {hashed}")
# Validate manually
if bcrypt.check_password_hash(hashed, password):
print("Password validation successful!")
else:
print("Password validation failed!")
Я уже много лет пытаюсь решить эту проблему, но не могу найти решение, может кто-нибудь мне помочь
Подробнее здесь: https://stackoverflow.com/questions/792 ... -plaintext
Мобильная версия