[Freeipa-devel] [PATCH 5 of 7] Fix not so random random passwords
Mark McLoughlin
markmc at redhat.com
Wed Jan 23 16:01:09 UTC 2008
# HG changeset patch
# User Mark McLoughlin <markmc at redhat.com>
# Date 1201020165 0
# Node ID 32943922b23b325fbc63527ba469c0a2fd0dd3d7
# Parent 2f52fe548d870069fdcea8ff9959007977f4da93
Fix not so random random passwords
If you run ipa_generate_password() multiple times, one
after the other, then you get the same password each time.
This is because it uses the current time to seed the
pseudo random number generator.
The easiest solution is to just use the default method
which seeds itself from /dev/urandom if available,
and uses a fractional time value otherwise.
Signed-off-by: Mark McLoughlin <markmc at redhat.com>
diff -r 2f52fe548d87 -r 32943922b23b ipa-python/ipautil.py
--- a/ipa-python/ipautil.py Tue Jan 22 11:58:06 2008 +0000
+++ b/ipa-python/ipautil.py Tue Jan 22 16:42:45 2008 +0000
@@ -24,8 +24,7 @@ import tempfile
import tempfile
import logging
import subprocess
-from random import Random
-from time import gmtime
+import random
import os, sys, traceback, readline
import stat
import shutil
@@ -364,8 +363,7 @@ def parse_generalized_time(timestr):
def ipa_generate_password():
rndpwd = ''
- r = Random()
- r.seed(gmtime())
+ r = random.Random()
for x in range(12):
# rndpwd += chr(r.randint(32,126))
rndpwd += chr(r.randint(65,90)) #stricter set for testing
More information about the Freeipa-devel
mailing list