diff --git a/.gitignore b/.gitignore index b6e4761..820353c 100644 --- a/.gitignore +++ b/.gitignore @@ -106,6 +106,7 @@ celerybeat.pid .venv env/ venv/ +myvenv/ ENV/ env.bak/ venv.bak/ diff --git a/README.md b/README.md index 99f1a41..f244f04 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ # password-manager-app Password Manager App with Flask and Python CRUD + +#### Aim +Explore the concept of CRUD using Flask and Flask SQLAlchemy ++ Create ++ Read ++ Update ++ Delete + +#### To Do ++ Add Exporting of password as json,csv ++ Add importing of json or csv to app ++ Encrypting of Password with Symmetric Encryption + + +#### . ++ By Jesse E. Agbe(JCharis) ++ Jesus Saves @ JCharisTech + + diff --git a/app.py b/app.py new file mode 100644 index 0000000..084facb --- /dev/null +++ b/app.py @@ -0,0 +1,103 @@ +from flask import Flask,render_template,request,url_for,flash,redirect,send_file +from flask_sqlalchemy import SQLAlchemy +from cryptography.fernet import Fernet +import csv +import time +timestr = time.strftime("%Y%m%d-%H%M%S") + + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' +app.config['SECRET_KEY'] = 'the random string' +db = SQLAlchemy(app) + +# Model +class PasswordManager(db.Model): + id = db.Column(db.Integer, primary_key=True) + email = db.Column(db.String(520), nullable=False) + site_url = db.Column(db.String(520), nullable=False) + site_password = db.Column(db.String(520), nullable=False) + + def __repr__(self): + return '' % self.email + +# from cryptography.fernet import Fernet +# key = Fernet.generate_key() +# with open("secret_key.txt","wb") as f: +# f.write(key) + +with open("secret_key.txt","rb") as f: + key = f.read() + + +def encrypt_password(key,data): + f = Fernet(key) + encrypted_token = f.encrypt(str(data).encode()) + return encrypted_token + + + + +@app.route("/") +def index(): + passwordlist = PasswordManager.query.all() + return render_template('index.html', passwordlist=passwordlist) + +@app.route("/add",methods=["GET","POST"]) +def add_password(): + if request.method == 'POST': + email = request.form['email'] + site_url = request.form['site_url'] + site_password = request.form['site_password'] + new_password_details = PasswordManager(email=email,site_url=site_url,site_password=site_password) + db.session.add(new_password_details) + db.session.commit() + flash("Password Added") + return redirect('/') + + +@app.route('/delete/') +def delete(id): + new_password_to_delete = PasswordManager.query.get_or_404(id) + + try: + db.session.delete(new_password_to_delete) + db.session.commit() + return redirect('/') + except: + return 'There was a problem deleting that task' + +@app.route('/update/', methods=['GET', 'POST']) +def update(id): + task = PasswordManager.query.get_or_404(id) + + if request.method == 'POST': + task.email = request.form['email'] + task.site_url = request.form['site_url'] + task.site_password = request.form['site_password'] + try: + db.session.commit() + flash("Password Updated") + return redirect('/') + except: + return 'There was an issue updating your task' + + else: + return render_template('update.html', task=task) + + +@app.route('/export') +def export_data(): + with open('dump.csv', 'w') as f: + out = csv.writer(f) + out.writerow(['id', 'email','site_url','site_password']) + for item in PasswordManager.query.all(): + out.writerow([item.id, item.email,item.site_url,item.site_password]) + return send_file('dump.csv', + mimetype='text/csv', + download_name=f"Export_Password_{timestr}.csv", + as_attachment=True) + + +if __name__ == "__main__": + app.run(debug=True) \ No newline at end of file diff --git a/data.db b/data.db new file mode 100644 index 0000000..d5e9a61 Binary files /dev/null and b/data.db differ diff --git a/dump.csv b/dump.csv new file mode 100644 index 0000000..903f3f4 --- /dev/null +++ b/dump.csv @@ -0,0 +1,3 @@ +id,email,site_url,site_password +1,test2@gmail.com,facebook.com,facebookhjhj +2,jch@gmail.com,jch.com,12345678 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e97791f Binary files /dev/null and b/requirements.txt differ diff --git a/secret_key.txt b/secret_key.txt new file mode 100644 index 0000000..7ff3067 --- /dev/null +++ b/secret_key.txt @@ -0,0 +1 @@ +TaGi6wX2Qic-S0WyhG5vtdHLxtApO_Wq7hvIbgeKNZM= \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..aa463a8 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,103 @@ + + + + + + + Password Master + + + + + +
+

Password Manager

+
+ +
+ +
+ +
+

+

+
+ +
+

Password Register

+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ + +
+ +
+ + + +
+ + + + + + + + + + + + + + {% for task in passwordlist %} + + + + + + + + + {% endfor %} +
EmailSite AddressSite PasswordActionsVisibility
{{ task.email }}{{ task.site_url }} + Delete +
+ Update +
+ Show Password +
+
+ +
+ + + + + + \ No newline at end of file diff --git a/templates/update.html b/templates/update.html new file mode 100644 index 0000000..48aeeb5 --- /dev/null +++ b/templates/update.html @@ -0,0 +1,61 @@ + + + + + + + Password Master + + + + + +
+

Password Manager

+ +
+ +
+ + Back + + + +
+
+ + +
+
+ + +
+
+ + +
+
+ Show Password +
+ +
+ +
+
+
+ + + + + + + \ No newline at end of file