Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kelvintechnical/password-generator


https://github.com/kelvintechnical/password-generator

Last synced: 27 days ago
JSON representation

Awesome Lists containing this project

README

        

Python Password Generator Web Application

Description


Python Password Generator is a Flask-based web application designed to create secure, customizable passwords based on a user-specified length. Users can generate passwords using letters, numbers, and special characters, providing an extra layer of security.

Prerequisites


To run this project, make sure you have Python and Flask installed on your system.




  • Install Flask: Run the following command to install Flask:
    pip install Flask


Installation




  1. Step 1: Clone the Repository

    • Clone the repository to your local machine:


    git clone https://github.com/yourusername/Password-Generator.git


  2. Navigate into the project directory:

  3. cd Password-Generator




  4. Step 2: Start the Flask Server

    • Start the Flask server by running:


    python app.py


  5. Once the server is running, open your browser and navigate to http://127.0.0.1:5000/.



Features




  • Customizable Password Length: Allows users to specify the desired length for a generated password.


  • Secure Password Generation: Generates passwords using a mix of letters, numbers, and symbols to enhance password strength.


  • Real-Time Interaction: Responds to user input instantly, generating a password upon request.


  • JSON Data Transfer: Returns the generated password in JSON format, making it easy to integrate with other applications.

Code Overview

Flask Backend


The Flask backend, defined in app.py, sets up the server and handles the logic for generating passwords.

from flask import Flask, render_template, request, jsonify

import string
import random

app = Flask(__name__)

def generate_password(length):
# Generates a secure password with letters, numbers, and symbols
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for _ in range(length))
return password

@app.route("/")
def index():
# Renders the main HTML page
return render_template('index.html')

@app.route('/generate', methods=['POST'])
def generate():
# Retrieves password length from the form and generates a password
length = int(request.form.get('length'))
password = generate_password(length)
return jsonify({'password': password})

if __name__ == '__main__':
app.run(debug=True)

Explanation:




  • generate_password function: Randomly generates a password of specified length using letters, digits, and punctuation characters.


  • Routes:


    • /: Displays the main page.


    • /generate: Processes the user’s input and returns a JSON response with the generated password.



HTML Frontend


The index.html file provides a form where users can enter their desired password length and submit to generate a password.

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Generator</title>
</head>
<body>
<h1>Password Generator</h1>
<form id="password-form">
<label for="length">Password Length:</label>
<input type="number" id="length" name="length" required>
<button type="submit">Generate Password</button>
</form>
<p id="result"></p>

<script>
document.getElementById('password-form').addEventListener('submit', function(event) {
event.preventDefault();
const length = document.getElementById('length').value;

fetch('/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ length: length }),
})
.then(response => response.json())
.then(data => {
document.getElementById('result').textContent = `Generated Password: ${data.password}`;
})
.catch(error => console.error('Error:', error));
});
</script>
</body>
</html>

---

Usage


To generate a password, make a POST request to the /generate endpoint with a length parameter.

Example Request


curl -X POST -d "length=12" http://127.0.0.1:5000/generate

Example Response


{

"password": "A@3g9#!aB$6f"
}

This example generates a 12-character password with a mix of letters, numbers, and symbols.

---

What I Learned




  • Flask Basics: Learned to initialize a Flask server, define routes, and manage requests.


  • Template Rendering: Used render_template to load HTML templates.


  • User Input Handling: Captured user input with request.form.get().


  • JSON Formatting: Used jsonify to send the password in JSON format.

Future Plans



  • Additional Customization: Add options to include or exclude specific types of characters.

  • Enhanced Styling: Improve the layout and design for a better user experience.

  • Password Management: Implement options to save and manage generated passwords securely.

Support & Feedback


If you found this project helpful, please consider leaving feedback to support my growth as a Python and Flask developer. Suggestions are always welcome!



Follow Me on X