diff options
author | Marian Sigler <m@qjym.de> | 2012-09-21 04:10:44 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-21 04:10:44 +0200 |
commit | 4febfc3be67c34dd6a9407effc83a4ea4e335da5 (patch) | |
tree | 5e08f5b86d0319ae08e07c2c89df6bfcb0860982 /utils.py | |
parent | 85b73458a145749f51b10a0b1d530cc43605d59c (diff) | |
download | web-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.py | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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)) |