mirror of
https://github.com/Steffo99/estus.git
synced 2024-11-25 00:54:18 +00:00
Add encryption
This commit is contained in:
parent
b8c742117f
commit
ac74f31b67
1 changed files with 9 additions and 7 deletions
16
server.py
16
server.py
|
@ -1,5 +1,6 @@
|
||||||
from flask import Flask, session, url_for, redirect, request, render_template, abort
|
from flask import Flask, session, url_for, redirect, request, render_template, abort
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
import bcrypt
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = "pepsecret"
|
app.secret_key = "pepsecret"
|
||||||
|
@ -13,7 +14,7 @@ db = SQLAlchemy(app)
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
uid = db.Column(db.Integer, primary_key=True)
|
uid = db.Column(db.Integer, primary_key=True)
|
||||||
username = db.Column(db.String(80), unique=True)
|
username = db.Column(db.String(80), unique=True)
|
||||||
passwd = db.Column(db.String(80))
|
passwd = db.Column(db.LargeBinary)
|
||||||
|
|
||||||
def __init__(self, username, passwd):
|
def __init__(self, username, passwd):
|
||||||
self.username = username
|
self.username = username
|
||||||
|
@ -94,9 +95,8 @@ class Dispositivo(db.Model):
|
||||||
|
|
||||||
|
|
||||||
class Accesso(db.Model):
|
class Accesso(db.Model):
|
||||||
aid = db.Column(db.Integer, primary_key=True)
|
iid = db.Column(db.Integer, db.ForeignKey('impiegato.iid'), primary_key=True)
|
||||||
iid = db.Column(db.Integer, db.ForeignKey('impiegato.iid'))
|
did = db.Column(db.Integer, db.ForeignKey('dispositivo.did'), primary_key=True)
|
||||||
did = db.Column(db.Integer, db.ForeignKey('dispositivo.did'))
|
|
||||||
|
|
||||||
def __init__(self, iid, did):
|
def __init__(self, iid, did):
|
||||||
self.iid = iid
|
self.iid = iid
|
||||||
|
@ -110,7 +110,7 @@ class Accesso(db.Model):
|
||||||
def login(username, password):
|
def login(username, password):
|
||||||
user = User.query.filter_by(username=username).first()
|
user = User.query.filter_by(username=username).first()
|
||||||
try:
|
try:
|
||||||
return password == user.passwd
|
return bcrypt.checkpw(bytes(password, encoding="utf-8"), user.passwd)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Se non esiste l'Utente
|
# Se non esiste l'Utente
|
||||||
return False
|
return False
|
||||||
|
@ -389,7 +389,9 @@ def page_details_host():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# db.create_all()
|
# db.create_all()
|
||||||
# u = User("lavaleria", "lava")
|
# p = b"admin"
|
||||||
# db.session.add(u)
|
# cenere = bcrypt.hashpw(p, bcrypt.gensalt())
|
||||||
|
# nuovouser = User('admin', cenere)
|
||||||
|
# db.session.add(nuovouser)
|
||||||
# db.session.commit()
|
# db.session.commit()
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
Loading…
Reference in a new issue