Browse Source

Add files via upload

main
Unbewohnte 4 years ago committed by GitHub
parent
commit
9d49f5ef29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      PasswordGenerator/forms.py
  2. 35
      PasswordGenerator/main.py
  3. 2
      PasswordGenerator/password_generator.py
  4. 3
      PasswordGenerator/static/styling.css
  5. 52
      PasswordGenerator/templates/homeen.html
  6. 52
      PasswordGenerator/templates/homeru.html

9
PasswordGenerator/forms.py

@ -10,3 +10,12 @@ class PasswordGenerationForm(FlaskForm):
Punctuation_field = BooleanField("Punctuation")
submit = SubmitField('Generate !')
valid = False
class PasswordGenerationFormRu(FlaskForm):
length = IntegerField('Длина (1-100(Числа))', validators = [DataRequired(),NumberRange(min=1,max=100)],default=10)
how_many_passwords = IntegerField('Как много паролей (1-20)',validators=[DataRequired(),NumberRange(min=1,max=20)],default=1)
Upper_register_field = BooleanField("Верхний регистр")
Digits_field = BooleanField("Цифры")
Punctuation_field = BooleanField("Пунктуация")
submit = SubmitField('Сгенерировать !')
valid = False

35
PasswordGenerator/main.py

@ -1,5 +1,5 @@
from flask import Flask,render_template, request
from forms import PasswordGenerationForm
from flask import Flask,render_template, request,redirect,url_for
from forms import PasswordGenerationForm,PasswordGenerationFormRu
from password_generator import generate
@ -7,8 +7,14 @@ application = Flask(__name__)
application.config['SECRET_KEY'] = '' #Generate your own
@application.route("/", methods= ['POST','GET'])
def mainpage():
@application.route("/",methods=['POST','GET'])
def redir():
return redirect(url_for('enpage'),code=302)
@application.route("/en", methods= ['POST','GET'])
def enpage():
form = PasswordGenerationForm()
if form.validate_on_submit():
form.valid = True
@ -21,7 +27,24 @@ def mainpage():
else:
form.valid = False
print('Something went wrong')
return render_template("home.html", form = form)
return render_template("homeen.html", form = form)
@application.route("/ru", methods= ['POST','GET'])
def rupage():
form = PasswordGenerationFormRu()
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("homeru.html", form = form)
@application.errorhandler(404)
def not_found(error):
@ -30,4 +53,4 @@ def not_found(error):
# Run Flask as Python script without any foreign commands
if __name__ == '__main__':
application.run(debug = True)
application.run(debug = False)

2
PasswordGenerator/password_generator.py

@ -13,7 +13,7 @@ digits_pun = list(string.ascii_lowercase*10 + string.digits*10 + string.punctuat
upp_pun = list(string.ascii_lowercase*10 + string.ascii_uppercase*10 +string.punctuation*5)
#Yeah, bad code, but couldn`t come up with a better idea
#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

3
PasswordGenerator/static/styling.css

@ -28,3 +28,6 @@ body{
width: 20px;
height:20px;
}
.langch{
color:blue;
}

52
PasswordGenerator/templates/homeen.html

@ -0,0 +1,52 @@
{% extends "layout.html" %}
{% block layout %}
<a href="/ru"class='langch'>Ru</a>
<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 %}

52
PasswordGenerator/templates/homeru.html

@ -0,0 +1,52 @@
{% extends "layout.html" %}
{% block layout %}
<a href="/en"class="langch">En</a>
<div class="container">
<h1>Генератор паролей</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</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</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>Сгенерированные пароли:</h3><br>
{%for password in form.password%}
<h3>{{password}}</h3><br>
{% endfor %}
</div>
{% endif %}
{% endblock layout %}
Loading…
Cancel
Save