From fa76863f884a27efca21372726f79508554e2f10 Mon Sep 17 00:00:00 2001 From: HamidAli110 <110588157+HamidAli110@users.noreply.github.com> Date: Sun, 15 Oct 2023 11:53:16 +0500 Subject: [PATCH] Create forget password restore .py --- forget password restore .py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 forget password restore .py diff --git a/forget password restore .py b/forget password restore .py new file mode 100644 index 00000000..4fe9fe6c --- /dev/null +++ b/forget password restore .py @@ -0,0 +1,33 @@ +import random +import string + +# Simulate a user database with email and password records +user_database = { + "user1@example.com": "password123", + "user2@example.com": "securepass", +} + +# Function to generate a random password +def generate_password(length=12): + return ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(length)) + +# Function to send a password reset email (you can reuse the previous email code) +def send_password_reset_email(email, reset_code): + # Implement the email sending code from the previous example + +# Function to reset the password +def reset_password(email, new_password): + # Update the user's password in the database + user_database[email] = new_password + +# Example usage +if __name__ == "__main__": + email = "user1@example.com" # This would typically come from the user's input + reset_code = "generated_reset_code" # This should match the code sent in the reset email + + if email in user_database: + new_password = generate_password() + reset_password(email, new_password) + print(f"Password reset for {email}. New password: {new_password}") + else: + print("Invalid email address.")