Mercurial > libervia-backend
diff src/tools/utils.py @ 2181:968b0d13bcc7
plugin account, tools: some cleaning account + email and password tools:
- plugin misc account has been reordered and cleaned a bit.
- new xmpp_domain setting is used to get the domain name of main XMPP server
- password generation method has been moved to tools.utils
- email sending method has been moved to tools.email
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 12 Mar 2017 19:32:59 +0100 |
parents | 0931b5a6213c |
children | 228d208fb5db |
line wrap: on
line diff
--- a/src/tools/utils.py Thu Mar 09 23:11:42 2017 +0100 +++ b/src/tools/utils.py Sun Mar 12 19:32:59 2017 +0100 @@ -26,6 +26,7 @@ import datetime import time import sys +import random def clean_ustr(ustr): @@ -54,6 +55,17 @@ template = u"{}T{}".format(template_date, template_time) if with_time else template_date return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template) +def generatePassword(vocabulary=None, size=20): + """Generate a password with random characters. + + @param vocabulary(iterable): characters to use to create password + @param size(int): number of characters in the password to generate + @return (unicode): generated password + """ + random.seed() + if vocabulary is None: + vocabulary = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)] + return u''.join([random.choice(vocabulary) for i in range(15)]) def getRepositoryData(module, as_string=True, is_path=False, save_dir_path=None): """Retrieve info on current mecurial repository