0
0
Flaskframework~30 mins

Password reset email pattern in Flask - Mini Project: Build & Apply

Choose your learning style9 modes available
Password Reset Email Pattern in Flask
📖 Scenario: You are building a simple Flask web app that allows users to reset their password by sending them a reset email link.This is a common feature in many websites where users can request a password reset if they forget their password.
🎯 Goal: Build a Flask route that sends a password reset email using a predefined email pattern.The email should include a reset link with a token for security.
📋 What You'll Learn
Create a Flask app with a route to handle password reset requests
Define a user email dictionary with sample users
Create a function to generate a reset token
Send an email message with the reset link using the token
💡 Why This Matters
🌍 Real World
Password reset is a critical feature in web applications to help users regain access securely.
💼 Career
Understanding how to implement password reset flows is important for backend web developers and security-conscious programmers.
Progress0 / 4 steps
1
Set up user email data
Create a dictionary called users with these exact entries: 'alice@example.com': 'Alice', 'bob@example.com': 'Bob', and 'carol@example.com': 'Carol'.
Flask
Need a hint?

Use a Python dictionary with the exact keys and values given.

2
Configure Flask app and secret key
Import Flask and request from flask. Create a Flask app instance called app. Then create a variable called SECRET_KEY and set it to the string 'mysecretkey'.
Flask
Need a hint?

Import Flask and request, then create app and secret key variables exactly as shown.

3
Create token generation function
Define a function called generate_token that takes an email parameter and returns a string combining the email and SECRET_KEY separated by a dash. Use an f-string for formatting.
Flask
Need a hint?

Use a function with one parameter and return the combined string using an f-string.

4
Create password reset route to send email
Create a Flask route @app.route('/reset_password', methods=['POST']). Define a function called reset_password that gets the email from request.form. If the email is in users, generate a token using generate_token(email). Then create a variable reset_link with the value f"http://example.com/reset?token={token}". Finally, create a variable email_message with the exact string f"Hi {users[email]}, click here to reset your password: {reset_link}".
Flask
Need a hint?

Use Flask route decorator and request.form.get to get email. Use the generate_token function and build the reset link and message exactly as shown.