Unbewohnte
4 years ago
committed by
GitHub
9 changed files with 233 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||||
|
from flask_wtf import FlaskForm |
||||||
|
from wtforms import StringField,SubmitField,TextAreaField,RadioField,IntegerField,BooleanField |
||||||
|
from wtforms.validators import DataRequired, Length, NumberRange |
||||||
|
|
||||||
|
class PasswordGenerationForm(FlaskForm): |
||||||
|
length = IntegerField('Length (1-100(Numbers only))', validators = [DataRequired(),NumberRange(min=1,max=100)],default=10) |
||||||
|
how_many_passwords = IntegerField('How many passwords (1-20)',validators=[DataRequired(),NumberRange(min=1,max=20)],default=1) |
||||||
|
Upper_register_field = BooleanField("Upper register") |
||||||
|
Digits_field = BooleanField("Digits") |
||||||
|
Punctuation_field = BooleanField("Punctuation") |
||||||
|
submit = SubmitField('Generate !') |
||||||
|
valid = False |
@ -0,0 +1,33 @@ |
|||||||
|
from flask import Flask,render_template, request |
||||||
|
from forms import PasswordGenerationForm |
||||||
|
from password_generator import generate |
||||||
|
|
||||||
|
|
||||||
|
application = Flask(__name__) |
||||||
|
application.config['SECRET_KEY'] = '' #Generate your own |
||||||
|
|
||||||
|
|
||||||
|
@application.route("/", methods= ['POST','GET']) |
||||||
|
def mainpage(): |
||||||
|
form = PasswordGenerationForm() |
||||||
|
if form.validate_on_submit(): |
||||||
|
form.valid = True |
||||||
|
Checkbox_values = [{'checkbox':'Upper_reg','value':request.form.get('Upper_register_field')}, |
||||||
|
{'checkbox':'Digits','value':request.form.get('Digits_field')}, |
||||||
|
{'checkbox':'Punctuation','value':request.form.get('Punctuation_field')}] |
||||||
|
len = int(request.form['length']) |
||||||
|
how_many = int(request.form['how_many_passwords']) |
||||||
|
form.password = generate(len,how_many=how_many,flags=Checkbox_values) |
||||||
|
else: |
||||||
|
form.valid = False |
||||||
|
print('Something went wrong') |
||||||
|
return render_template("home.html", form = form) |
||||||
|
|
||||||
|
@application.errorhandler(404) |
||||||
|
def not_found(error): |
||||||
|
return render_template('not_found404.html',error = error) |
||||||
|
|
||||||
|
|
||||||
|
# Run Flask as Python script without any foreign commands |
||||||
|
if __name__ == '__main__': |
||||||
|
application.run(debug = True) |
@ -0,0 +1,84 @@ |
|||||||
|
import random |
||||||
|
import string |
||||||
|
|
||||||
|
|
||||||
|
digits = list(string.digits*10 + string.ascii_lowercase*10) |
||||||
|
uppercase = list(string.ascii_uppercase + string.ascii_lowercase)*30 |
||||||
|
lowercase = list(string.ascii_lowercase)*30 |
||||||
|
punct = list(string.ascii_lowercase*10 + string.punctuation*5) |
||||||
|
|
||||||
|
upp_dig = list(string.digits*10 + string.ascii_lowercase*10 + string.ascii_uppercase*10) |
||||||
|
upp_dig_pun = list(string.digits*10 + string.ascii_lowercase*10 + string.ascii_uppercase*10 + string.punctuation*5) |
||||||
|
digits_pun = list(string.ascii_lowercase*10 + string.digits*10 + string.punctuation*5) |
||||||
|
upp_pun = list(string.ascii_lowercase*10 + string.ascii_uppercase*10 +string.punctuation*5) |
||||||
|
|
||||||
|
|
||||||
|
#Yeah, spaghetti code, but couldn`t come up with a better idea |
||||||
|
def generate(LEN,flags=None,how_many=None): |
||||||
|
passwords = [] |
||||||
|
U,D,P = None,None,None |
||||||
|
for flag_dict in flags: |
||||||
|
if flag_dict['checkbox'] == 'Upper_reg' and flag_dict['value'] == 'y': |
||||||
|
U = True |
||||||
|
elif flag_dict['checkbox'] == 'Digits' and flag_dict['value'] == 'y': |
||||||
|
D = True |
||||||
|
elif flag_dict['checkbox'] == 'Punctuation' and flag_dict['value'] == 'y': |
||||||
|
P = True |
||||||
|
|
||||||
|
if U == None and D == None and P == None: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(lowercase ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == True and D == None and P == None: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(uppercase ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == None and D == True and P == None: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(digits ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == None and D == None and P == True: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(punct ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == True and D == True and P == None: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(upp_dig ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == None and D == True and P == True: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(digits_pun ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == True and D == None and P == True: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(upp_pun ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
|
||||||
|
elif U == True and D == True and P == True: |
||||||
|
for password in range(int(how_many)): |
||||||
|
password = random.sample(upp_dig_pun ,int(LEN)) |
||||||
|
password = ''.join(password) |
||||||
|
passwords.append(password) |
||||||
|
return passwords |
||||||
|
else: |
||||||
|
print("Error!") |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 15 KiB |
@ -0,0 +1,30 @@ |
|||||||
|
body{ |
||||||
|
text-align: center; |
||||||
|
text-shadow: 5px; |
||||||
|
background-color: #CAD2D0; |
||||||
|
font-size: 20px; |
||||||
|
} |
||||||
|
.container{ |
||||||
|
margin-top: 50px; |
||||||
|
padding-bottom: 10px; |
||||||
|
} |
||||||
|
#submit{ |
||||||
|
margin-top: 20px; |
||||||
|
} |
||||||
|
|
||||||
|
#output{ |
||||||
|
/* margin-top:50px; */ |
||||||
|
width: 460px; |
||||||
|
height: 50px; /*100px;*/ |
||||||
|
resize: none; |
||||||
|
} |
||||||
|
#output_label{ |
||||||
|
margin-top:50px; |
||||||
|
} |
||||||
|
#invalid_value{ |
||||||
|
color: red; |
||||||
|
} |
||||||
|
.check{ |
||||||
|
width: 20px; |
||||||
|
height:20px; |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
{% extends "layout.html" %} |
||||||
|
|
||||||
|
{% block layout %} |
||||||
|
<div class="container"> |
||||||
|
<h1>Password generator</h1> |
||||||
|
<form class="" method="POST"> |
||||||
|
{{ form.hidden_tag() }} |
||||||
|
|
||||||
|
|
||||||
|
<div class=""> |
||||||
|
{{form.length.label(class="form-control-label")}}<br> |
||||||
|
{{form.length(class="form-control-label")}}<br> |
||||||
|
|
||||||
|
{% if form.length.errors %} |
||||||
|
<h3 id = 'invalid_value'>Invalid value</h3> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{{form.how_many_passwords.label(class="form-control-label")}}<br> |
||||||
|
{{form.how_many_passwords(class="form-control-label")}}<br> |
||||||
|
|
||||||
|
{% if form.how_many_passwords.errors %} |
||||||
|
<h3 id = 'invalid_value'>Invalid value</h3><br> |
||||||
|
{% endif %} |
||||||
|
|
||||||
|
{{ form.Upper_register_field.label}} |
||||||
|
{{ form.Upper_register_field(class="check")}}<br> |
||||||
|
|
||||||
|
{{ form.Digits_field.label }} |
||||||
|
{{ form.Digits_field(class="check") }}<br> |
||||||
|
|
||||||
|
{{ form.Punctuation_field.label}} |
||||||
|
{{ form.Punctuation_field(class="check") }}<br> |
||||||
|
|
||||||
|
</div> |
||||||
|
|
||||||
|
<div class=""> |
||||||
|
{{form.submit(class="btn btn-outline-info")}}<br> |
||||||
|
</div> |
||||||
|
</form> |
||||||
|
</div> |
||||||
|
|
||||||
|
{% if form.valid == True %} |
||||||
|
<div class=""> |
||||||
|
<h3>Generated passwords:</h3><br> |
||||||
|
|
||||||
|
{%for password in form.password%} |
||||||
|
<h3>{{password}}</h3><br> |
||||||
|
{% endfor %} |
||||||
|
</div> |
||||||
|
{% endif %} |
||||||
|
{% endblock layout %} |
@ -0,0 +1,15 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html lang="en" dir="ltr"> |
||||||
|
<head> |
||||||
|
<meta charset="utf-8"> |
||||||
|
<title>Password Generator</title> |
||||||
|
<link rel="icon" href="static/favicon.ico"> |
||||||
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> |
||||||
|
<link rel="stylesheet" href="/static/styling.css" type="text/css"> |
||||||
|
|
||||||
|
</head> |
||||||
|
<body> |
||||||
|
{% block layout %} |
||||||
|
{% endblock %} |
||||||
|
</body> |
||||||
|
</html> |
Loading…
Reference in new issue