Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-KartikSharma authored Dec 10, 2024
1 parent e17028e commit 3c6315b
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
35 changes: 35 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask import Flask, request, jsonify
import random
import string

app = Flask(__name__)

def generate_password(length, use_uppercase, use_numbers, use_special):
characters = string.ascii_lowercase
if use_uppercase:
characters += string.ascii_uppercase
if use_numbers:
characters += string.digits
if use_special:
characters += "!@#$%^&*()"

password = ''.join(random.choice(characters) for _ in range(length))
return password

@app.route('/')
def home():
return app.send_static_file('index.html')

@app.route('/generate', methods=['POST'])
def generate():
data = request.get_json() # Correct way to get JSON data
length = int(data.get('length', 12))
use_uppercase = data.get('use_uppercase', True)
use_numbers = data.get('use_numbers', True)
use_special = data.get('use_special', True)

password = generate_password(length, use_uppercase, use_numbers, use_special)
return jsonify({"password": password})

if __name__ == '__main__':
app.run(debug=True)
114 changes: 114 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Generator by - KARTIK SHARMA</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f7f7f7;
font-family: Arial, sans-serif;
}
.container {
max-width: 500px;
margin-top: 50px;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
}
.result {
margin-top: 20px;
font-size: 18px;
text-align: center;
font-weight: bold;
}
#dark-mode-btn {
position: absolute;
top: 10px;
right: 10px;
background-color: #444;
color: white;
border: none;
padding: 10px;
border-radius: 5px;
}
body.dark-mode {
background-color: #333;
color: #ddd;
}
.container.dark-mode {
background-color: #444;
color: #eee;
}
</style>
</head>
<body>
<button id="dark-mode-btn">Dark Mode</button>
<div class="container">
<h3>Password Generator</h3>
<div class="mb-3">
<label for="password-length">Length:</label>
<input type="number" id="password-length" value="12" min="6" max="20">
</div>
<div class="form-check">
<input type="checkbox" id="uppercase" checked>
<label for="uppercase">Include Uppercase Letters</label>
</div>
<div class="form-check">
<input type="checkbox" id="numbers" checked>
<label for="numbers">Include Numbers</label>
</div>
<div class="form-check">
<input type="checkbox" id="special" checked>
<label for="special">Include Special Characters</label>
</div>
<button id="generate-password" class="btn btn-primary mt-3">Generate</button>
<div class="result" id="password-result"></div>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script>

// dark mode
let darkMode = false;
const darkModeBtn = document.getElementById('dark-mode-btn');
const body = document.body;
const container = document.querySelector('.container');

darkModeBtn.onclick = function() {
darkMode = !darkMode;
body.classList.toggle('dark-mode', darkMode);
container.classList.toggle('dark-mode', darkMode);
darkModeBtn.textContent = darkMode ? 'Light Mode' : 'Dark Mode';
};

// passowrd generate fnctn
document.getElementById('generate-password').onclick = function() {
const length = document.getElementById('password-length').value;
const useUppercase = document.getElementById('uppercase').checked;
const useNumbers = document.getElementById('numbers').checked;
const useSpecial = document.getElementById('special').checked;

const lowercase = 'abcdefghijklmnopqrstuvwxyz';
const uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numbers = '0123456789';
const specialChars = '!@#$%^&*()_+-=[]{}|;:,.<>?';

let characters = lowercase;
if (useUppercase) characters += uppercase;
if (useNumbers) characters += numbers;
if (useSpecial) characters += specialChars;

let password = '';
for (let i = 0; i < length; i++) {
password += characters.charAt(Math.floor(Math.random() * characters.length));
}

// output password
document.getElementById('password-result').textContent = password;
};
</script>
</body>
</html>

0 comments on commit 3c6315b

Please sign in to comment.