diff --git a/README.md b/README.md index 10e4723..3dd44d9 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ on pourrait ajoute de la double authentification mais bon ... ### Sur OpenBSD (7.1) Il faut installer FLask et quelques dépendances pkg_add py3-werkzeug py3-jinja2 py3-Pillow py3-wtforms py3-flask-wtf py3-flask \ - py3-bcrypt py3-markdown py3-gevent py3-zopeinterface + py3-bcrypt py3-markdown py3-gevent py3-zopeinterface py3-qrcode Il reste malheuresment une dépendances sur flask-bcrypt a installé avec pip: @@ -21,7 +21,7 @@ Il reste malheuresment une dépendances sur flask-bcrypt a installé avec pip: ### Sur Debian apt install python3-flask python3-flask-bcrypt python3-wtforms python3-pil python3-markdown \ - python3-gevent python3-zope.interface + python3-gevent python3-zope.interface python3-qrcode ## Démarrer le programme : diff --git a/templates/mypassword.html b/templates/mypassword.html index c8084f0..93d8371 100644 --- a/templates/mypassword.html +++ b/templates/mypassword.html @@ -27,9 +27,11 @@

Votre clef secrète : {{ totp_shared_key }}

+ {% if shared_key_validate %}

Votre clef secrète est valide et activé

{% else %} +

Votre clef secrète n'est pas validé et donc non active

{% endif %} @@ -41,6 +43,9 @@ + + + {% if shared_key_validate %}

Si vous voulez changer votre clef secrète vous devez d'abord supprimé votre clef actuelle

diff --git a/views/profil.py b/views/profil.py index 1c9d40f..8f1c6c5 100644 --- a/views/profil.py +++ b/views/profil.py @@ -10,6 +10,8 @@ from socket import gethostname from flask_bcrypt import Bcrypt from tools.utils import email_disp, append_to_log, gen_token, valid_passwd, valid_token_register, get_user_by_token, totp_is_valid from pyotp import random_base32 +import qrcode + profil = Blueprint('profil', __name__, template_folder='templates') @@ -195,6 +197,8 @@ def change_passwd() : if not(account['totp']): account['totp'] = random_base32() + img = qrcode.make('otpauth://totp/'+BASE_URL+'?secret='+account['totp']) + img.save(DOSSIER_PERSO + user + "/totp.png") shared_key_validate = False return render_template('mypassword.html', @@ -203,7 +207,8 @@ def change_passwd() : alias=account['alias'], totp_shared_key=account['totp'], shared_key_validate=shared_key_validate, - username=user) + username=user, + base_url=BASE_URL) else : return redirect(BASE_URL, code=401) @@ -301,6 +306,8 @@ def set_totp(): print("shared_key: " +shared_key) cursor.execute("""UPDATE users SET totp=? WHERE name=?""", (shared_key, user,)) conn.commit() + img = qrcode.make('otpauth://totp/'+BASE_URL+'?secret='+shared_key) + img.save(DOSSIER_PERSO + user + "/totp.png") flash(u'Votre mot de passe à usage unique est configuré et actif.', 'success') else: flash(u'Le code de validation totp n\'est pas valide.', 'error') @@ -321,6 +328,16 @@ def del_totp(): conn.close() return redirect(url_for('profil.change_passwd', _external=True)) + +@profil.route('/totp.png', methods=['GET']) +def totp_qrcode(): + if 'username' in session : + user='%s' % escape(session['username']) + return send_file( + os.path.join(DOSSIER_PERSO, user, "totp.png"), "totp.png") + else : + return redirect(BASE_URL, code=401) + @profil.route('/deltoken-password-lost/', methods=['GET','POST'] ) def deltoken_passwd_lost(token) :