Revision ce55f211 snf-cyclades-app/synnefo/api/util.py
b/snf-cyclades-app/synnefo/api/util.py | ||
---|---|---|
106 | 106 |
|
107 | 107 |
def random_password(): |
108 | 108 |
"""Generates a random password |
109 |
|
|
109 |
|
|
110 | 110 |
We generate a windows compliant password: it must contain at least |
111 | 111 |
one charachter from each of the groups: upper case, lower case, digits. |
112 | 112 |
""" |
113 |
|
|
113 |
|
|
114 | 114 |
pool = lowercase + uppercase + digits |
115 | 115 |
lowerset = set(lowercase) |
116 | 116 |
upperset = set(uppercase) |
117 | 117 |
digitset = set(digits) |
118 | 118 |
length = 10 |
119 |
|
|
119 |
|
|
120 | 120 |
password = ''.join(choice(pool) for i in range(length - 2)) |
121 |
|
|
121 |
|
|
122 | 122 |
# Make sure the password is compliant |
123 | 123 |
chars = set(password) |
124 | 124 |
if not chars & lowerset: |
... | ... | |
127 | 127 |
password += choice(uppercase) |
128 | 128 |
if not chars & digitset: |
129 | 129 |
password += choice(digits) |
130 |
|
|
130 |
|
|
131 | 131 |
# Pad if necessary to reach required length |
132 | 132 |
password += ''.join(choice(pool) for i in range(length - len(password))) |
133 |
|
|
133 |
|
|
134 | 134 |
return password |
135 | 135 |
|
136 | 136 |
|
... | ... | |
238 | 238 |
|
239 | 239 |
if settings.TEST: |
240 | 240 |
response['Date'] = format_date_time(time()) |
241 |
|
|
241 |
|
|
242 | 242 |
add_never_cache_headers(response) |
243 | 243 |
|
244 | 244 |
|
Also available in: Unified diff