From 8667f788f157faa998703a38edcdbabe2eea1f8e Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Thu, 10 Nov 2016 08:11:25 +0100 Subject: [PATCH] Add password support --- README.md | 1 + index.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index f3fedae..fea4f26 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ TBA ## Requirements +* passlib >= 1.6.0 * py-flask >= 0.10 * py-flask-wtf >= 0.10 * py-ldap >= 2.4.15 diff --git a/index.py b/index.py index 227df47..74d3e25 100755 --- a/index.py +++ b/index.py @@ -4,6 +4,8 @@ from flask import Flask, render_template, redirect, url_for, session from flask_wtf import Form import ldap import ldap.modlist +import os +from passlib.hash import ldap_salted_sha1 from redis import Redis import uuid from wtforms.fields import IntegerField, PasswordField, SelectField, StringField, SubmitField @@ -43,6 +45,9 @@ class LoginForm(Form): submit = SubmitField('Login') +def makeSecret(password): + return ldap_salted_sha1.encrypt(password) + def isAdmin(): return isLoggedin() and rdb.hget(session['uuid'], 'user') in app.config.get('ADMINS', []) @@ -85,6 +90,7 @@ def create(): 'uid' : form.uid.data, 'gn' : form.gn.data, 'sn' : form.sn.data, + 'pass' : makeSecret(form.pwd1.data) } # add user