Fixed random password complexity

This commit is contained in:
Adolfo Gómez García 2020-08-18 00:47:56 +02:00
parent 2529039f49
commit 416b5e738f

View File

@ -91,7 +91,12 @@ class WinRandomPassManager(WindowsOsManager):
def genPassword(self, userService: 'UserService'):
randomPass = userService.recoverValue('winOsRandomPass')
if not randomPass:
randomPass = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(16))
# Generates a password that conforms to complexity
rnd = random.SystemRandom()
base = ''.join(rnd.choice(v) for v in (string.ascii_lowercase, string.ascii_uppercase, string.digits)) + rnd.choice('.+-')
randomPass = ''.join(rnd.choice(string.ascii_letters + string.digits) for _ in range(13))
pos = rnd.randrange(0, len(randomPass))
randomPass = randomPass[:pos] + base + randomPass[pos:]
userService.storeValue('winOsRandomPass', randomPass)
log.doLog(userService, log.INFO, "Password set to \"{}\"".format(randomPass), log.OSMANAGER)
return randomPass