diff --git a/PasswordGenerator/forms.py b/PasswordGenerator/forms.py new file mode 100644 index 0000000..460c2eb --- /dev/null +++ b/PasswordGenerator/forms.py @@ -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 diff --git a/PasswordGenerator/main.py b/PasswordGenerator/main.py new file mode 100644 index 0000000..0da8e2f --- /dev/null +++ b/PasswordGenerator/main.py @@ -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) diff --git a/PasswordGenerator/password_generator.py b/PasswordGenerator/password_generator.py new file mode 100644 index 0000000..ad8944a --- /dev/null +++ b/PasswordGenerator/password_generator.py @@ -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!") diff --git a/PasswordGenerator/static/favicon.ico b/PasswordGenerator/static/favicon.ico new file mode 100644 index 0000000..e18d069 Binary files /dev/null and b/PasswordGenerator/static/favicon.ico differ diff --git a/PasswordGenerator/static/favicon.png b/PasswordGenerator/static/favicon.png new file mode 100644 index 0000000..26c7f28 Binary files /dev/null and b/PasswordGenerator/static/favicon.png differ diff --git a/PasswordGenerator/static/styling.css b/PasswordGenerator/static/styling.css new file mode 100644 index 0000000..73d34c7 --- /dev/null +++ b/PasswordGenerator/static/styling.css @@ -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; +} diff --git a/PasswordGenerator/templates/home.html b/PasswordGenerator/templates/home.html new file mode 100644 index 0000000..3ddc09f --- /dev/null +++ b/PasswordGenerator/templates/home.html @@ -0,0 +1,51 @@ +{% extends "layout.html" %} + +{% block layout %} +
+

Password generator

+
+ {{ form.hidden_tag() }} + + +
+ {{form.length.label(class="form-control-label")}}
+ {{form.length(class="form-control-label")}}
+ + {% if form.length.errors %} +

Invalid value

+ {% endif %} + + {{form.how_many_passwords.label(class="form-control-label")}}
+ {{form.how_many_passwords(class="form-control-label")}}
+ + {% if form.how_many_passwords.errors %} +

Invalid value


+ {% endif %} + + {{ form.Upper_register_field.label}} + {{ form.Upper_register_field(class="check")}}
+ + {{ form.Digits_field.label }} + {{ form.Digits_field(class="check") }}
+ + {{ form.Punctuation_field.label}} + {{ form.Punctuation_field(class="check") }}
+ +
+ +
+ {{form.submit(class="btn btn-outline-info")}}
+
+
+
+ + {% if form.valid == True %} +
+

Generated passwords:


+ + {%for password in form.password%} +

{{password}}


+ {% endfor %} +
+ {% endif %} +{% endblock layout %} diff --git a/PasswordGenerator/templates/layout.html b/PasswordGenerator/templates/layout.html new file mode 100644 index 0000000..634543b --- /dev/null +++ b/PasswordGenerator/templates/layout.html @@ -0,0 +1,15 @@ + + + + + Password Generator + + + + + + + {% block layout %} + {% endblock %} + + diff --git a/PasswordGenerator/templates/not_found404.html b/PasswordGenerator/templates/not_found404.html new file mode 100644 index 0000000..7a054b4 --- /dev/null +++ b/PasswordGenerator/templates/not_found404.html @@ -0,0 +1,8 @@ +{% extends "layout.html" %} + +{% block layout %} +
+

404

+

Not found, check your spelling

+
+{% endblock layout %}