summaryrefslogtreecommitdiffstats
path: root/utils.py
diff options
context:
space:
mode:
authorMarian Sigler <m@qjym.de>2012-09-21 04:10:44 +0200
committerMarian Sigler <m@qjym.de>2012-09-21 04:10:44 +0200
commit4febfc3be67c34dd6a9407effc83a4ea4e335da5 (patch)
tree5e08f5b86d0319ae08e07c2c89df6bfcb0860982 /utils.py
parent85b73458a145749f51b10a0b1d530cc43605d59c (diff)
downloadweb-4febfc3be67c34dd6a9407effc83a4ea4e335da5.tar.gz
web-4febfc3be67c34dd6a9407effc83a4ea4e335da5.tar.bz2
web-4febfc3be67c34dd6a9407effc83a4ea4e335da5.zip
basic settings (yet without confirmation mail on mail change etc)
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index da6d741..c6737b8 100644
--- a/utils.py
+++ b/utils.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import ldap
+import re
from functools import wraps
from flask import flash, g, redirect, render_template, request, session, url_for
from random import randint
@@ -8,6 +9,8 @@ from werkzeug.exceptions import Forbidden
+_username_re = re.compile(r'^[a-z]{2,16}')
+
# using http://flask.pocoo.org/docs/patterns/viewdecorators/
def templated(template=None):
def templated_(f):
@@ -50,6 +53,7 @@ def login_user(username, password):
def logout_user():
session.pop('username', None)
session.pop('password', None)
+ g.user = None
def pad(s, numbytes=32, padding='\0'):
@@ -62,6 +66,9 @@ def encrypt_password(password):
"""
assert len(app.config['PASSWORD_ENCRYPTION_KEY']) == 32
+ if isinstance(password, unicode):
+ password = password.encode('utf8')
+
iv = ''.join(chr(randint(0, 0xff)) for i in range(16))
encryptor = AES.new(app.config['PASSWORD_ENCRYPTION_KEY'], AES.MODE_CBC, iv)
return iv + encryptor.encrypt(pad(password))