From f1df89e5a8ee5e6d9c58bf2d2c23268bc48e1d15 Mon Sep 17 00:00:00 2001 From: Unbewohnte <65883674+Unbewohnte@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:59:55 +0300 Subject: [PATCH] Add files via upload --- PasswordGenerator/forms.py | 12 +++ PasswordGenerator/main.py | 33 +++++++ PasswordGenerator/password_generator.py | 84 ++++++++++++++++++ PasswordGenerator/static/favicon.ico | Bin 0 -> 1150 bytes PasswordGenerator/static/favicon.png | Bin 0 -> 15427 bytes PasswordGenerator/static/styling.css | 30 +++++++ PasswordGenerator/templates/home.html | 51 +++++++++++ PasswordGenerator/templates/layout.html | 15 ++++ PasswordGenerator/templates/not_found404.html | 8 ++ 9 files changed, 233 insertions(+) create mode 100644 PasswordGenerator/forms.py create mode 100644 PasswordGenerator/main.py create mode 100644 PasswordGenerator/password_generator.py create mode 100644 PasswordGenerator/static/favicon.ico create mode 100644 PasswordGenerator/static/favicon.png create mode 100644 PasswordGenerator/static/styling.css create mode 100644 PasswordGenerator/templates/home.html create mode 100644 PasswordGenerator/templates/layout.html create mode 100644 PasswordGenerator/templates/not_found404.html 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 0000000000000000000000000000000000000000..e18d0695e77c2f3e5223cb81f6a6b6f4e11c1f10 GIT binary patch literal 1150 zcmd6kO-mbL5XYZ_;7vSvtw+Cw9*aeZ^(`SLZq_6w*(7V4mrXWlf^AHFi5SH%Pz6Eo zBIw0SYtXc`)c77zL<^NjDbicL{hiGk@bCoj<}S0dJ2StT|2)gs3%VN{89kestB$cI z##jp(g(#xO$+0%dZ8hkoeLts5&CSCRPeP0(Fc?uW5L94(8`dotfuN|cgrab#-h-!G zV?t9i=<^5g#wEc--XsUn>l?vq(E$U+%+yC7o8a=!M2dQkB1Ag0I{U{gIzFwSCmch! z$B%ZKoxBf&A%)9(NS8?Zy~GKzcd%>}VEDWPV=@hEIEoJYFxrJ72=va=?;TAekj+(Q zn`wsqo{ugpqgRsANqnDIhW|r`%X?@qs}hG8jicM`g_+K(YiSk6Kp3yAHgq~%=yJMY z81``a^}`d$bbf-Gq#6mvks$4p!T|M=(&MyK0#arYN@0)7JH8$wU;fL@J=|B=-sjd> zw)T%x8{9Nf50zXRJn(5;UnDV>aT$MNF_po_=Q?o|cK0yB_zenWf3Dlj_nrwB3 zSU9NsclWm=%$6>ZJ-UF6`Whe6R^>In_WMs|Pv7_BieEgxdUWnX{weRE&YFFxuWiNu Tj1|kem5Yr1d&$^stIpj4jMpKb literal 0 HcmV?d00001 diff --git a/PasswordGenerator/static/favicon.png b/PasswordGenerator/static/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..26c7f28b59250acc6d4e8e7a7f770b868df16a3e GIT binary patch literal 15427 zcmeI3e{2+G8pns=4`@VDF`&q~w?Ng(?9A+Te@(VaOPA7KZm?I1v_{3*nRnZf-I?vo zw7acA5Q+RU2zV!moOd=S9vt!fmHIm-7OIH~!C(aq;&EbVV?aP|d&eR7&hB=1`?h`U z<-9*k-br?6pZEJd&-=cg_j#Y4e`a0n!UdCxZYrWEYEn&gs1DvITb~J6!0%hmT@vAK zV!XQ1ps1_&TAy*hyW{HV6y-ml)Hj$7!moKri#bGD3j;?o7KgnlDlj)07o}yuw1q*F zqL$fDzxA%&rpRUXC2oNg;+3FTsqWChqK<|2QpYmMFWct^ivmd=28aPuv?XIv)!>t5 z_H2(`9KO$Ro&!%a)9le2mK4$fWb=eRjGC(F4Qj%A#F zn&bFVFVA^w*~=a*g1-W~9O3IiRoUU7Rc3EC%{b36iA2JYa5*%+iQ)WyKf^j1r;~;~ zXro;<#U!m7Gc!R3 zc(?lw*2S}IL6A&OB!&RfUKUMpEK!E^MdN6)5@{b(lzh*jF$96HQ4Ld6B~TLz!nHdT zMdsa3pCr0OFCFoS9PJC2MreQ7Dbo?o?@avU~Lc2Jp z&mVEoK9Ac+hh3#!TJ-w7wAbVJ!x3G65x53J7q|}#eW$L#A|yr&`dG97Z-*Em%&?)V z6$7SDdqGOU#7dW$MWAJ9>!1)-(&Zv9>ISe*VVQmK80P9ru6$TN>C?=Ml2vGel9j7K z4lqMn^V7xC1|F8#!*!Dl}z?hEE&wU5-xhpk`Y7>xy%wXCMHjHi4GFv(HJPnqC;pZ

4GMMAS^H=H5YhU|35se4KPo|^qJ%W z%&<1Je}i?#qpj)weh&*T_@Dx>tZSi+x;Eln3uV+b@3~l2%%C$n8q!?gW&KHJU@U^q zb0Fw(yIt-8gEpfcwMr618$t@K=Z00KI8W9G6-IPy9L=#n$U0_Hq2S3YeY`WR@VO2? zQZl(`%3&uzR~vuIANdvilu?mbWDo=h-Xys2d=Qo3LV(~+f(y?FQ3);t2;L;P@O%)J z;6i}lO@a&02T=(w1PINb zpO@ghkD^*xit4|gqWEnTHC5ZPbYB%kjXPBns;EzX{--D2xpUEPruD2yUHA)4-@U1* zxpY%;anf4il+^}K8DaWj;CD-3L?cN!WRSD*8hv%_3Ja_DT?}rzC zDc?lli| zQs>bby)Zwc(blR+M&bO1=IN*z(b>d-m-4L`_ZJwZ8L# zX>azt_r@>g%{tWE|LPa_dOYu*9jKwFPrkL}#98jRZ|}LNdXKT~sV#Hv3kbjb!-8M2 z!XtfsN22B1cbX55FW$J7oiu*JxQ0t_ulqZ{a&Kz+qurvXeC=hzYcI}tnqA+1zPIzG z+0!ncICsI!)stU;q5Igu&r;pj)j78A@^-E5Tpii*@g1ahC6|d)E?!{%{doPxKQA3meOdX*@e=3Rp!J$> N&HRO-7v|l+>OTSF6lDMa literal 0 HcmV?d00001 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 %}