This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
mandaye/crypt_pwd.py

36 lines
907 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Script to crypt mandaye passwords
"""
import base64
import logging
from Crypto.Cipher import AES
from mandaye import config
from mandaye.models import ExtUser
from mandaye.db import sql_session
def encrypt_pwd(pwd):
logging.debug("Encrypt password")
enc_pwd = pwd
if config.encrypt_secret:
try:
cipher = AES.new(config.encrypt_secret, AES.MODE_CFB)
enc_pwd = cipher.encrypt(pwd)
enc_pwd = base64.b64encode(enc_pwd)
except Exception, e:
if config.debug:
traceback.print_exc()
logging.warning('Password encrypting failed %s' % e)
else:
logging.warning("You must set a secret to use pwd encryption")
return enc_pwd
for user in sql_session().query(ExtUser).all():
user.password = encrypt_pwd(user.password)
sql_session().commit()