summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-03-16 18:42:41 +0000
committerTarmac <>2011-03-16 18:42:41 +0000
commitdfd0e8a32ae40043a78c12fb871c11bb9bd0f4c3 (patch)
tree3b68053d9e0b0d8cf92058b2781f9755a4c2595d /nova/utils.py
parent7dec290a12603200b45832f43755e6d7fa88980e (diff)
parent22aad6700124411aceed0b2bd3953cbbc48b6130 (diff)
downloadnova-dfd0e8a32ae40043a78c12fb871c11bb9bd0f4c3.tar.gz
nova-dfd0e8a32ae40043a78c12fb871c11bb9bd0f4c3.tar.xz
nova-dfd0e8a32ae40043a78c12fb871c11bb9bd0f4c3.zip
Don't generate insecure passwords where it's easy to use urandom instead
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 87e726394..199ee8701 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -262,13 +262,25 @@ def generate_mac():
return ':'.join(map(lambda x: "%02x" % x, mac))
-def generate_password(length=20):
- """Generate a random sequence of letters and digits
- to be used as a password. Note that this is not intended
- to represent the ultimate in security.
+# Default symbols to use for passwords. Avoids visually confusing characters.
+# ~6 bits per symbol
+DEFAULT_PASSWORD_SYMBOLS = ("23456789" # Removed: 0,1
+ "ABCDEFGHJKLMNPQRSTUVWXYZ" # Removed: I, O
+ "abcdefghijkmnopqrstuvwxyz") # Removed: l
+
+
+# ~5 bits per symbol
+EASIER_PASSWORD_SYMBOLS = ("23456789" # Removed: 0, 1
+ "ABCDEFGHJKLMNPQRSTUVWXYZ") # Removed: I, O
+
+
+def generate_password(length=20, symbols=DEFAULT_PASSWORD_SYMBOLS):
+ """Generate a random password from the supplied symbols.
+
+ Believed to be reasonably secure (with a reasonable password length!)
"""
- chrs = string.letters + string.digits
- return "".join([random.choice(chrs) for i in xrange(length)])
+ r = random.SystemRandom()
+ return "".join([r.choice(symbols) for _i in xrange(length)])
def last_octet(address):