def disable_user(uid): random_pass = "".join( random.choices( string.ascii_uppercase + string.ascii_lowercase + string.digits + SPECIAL_CHARS, k=8, )) # assure there must be at least one character from each group random_pass = random_pass + ''.join([ random.choice(chars) for chars in [ string.ascii_lowercase, string.digits, string.ascii_uppercase, SPECIAL_CHARS ] ]) random_pass = ''.join(random.sample(random_pass, len(random_pass))) update_user( user_id=[ str(uid), ], password=random_pass, )
roles = db_roles() rid = roles["administrator"] set_user_role( user_id=[ str(uid), ], role_ids=[ str(rid), ], ) else: # modify an existing user ("wazuh" or "wazuh-wui") uid = initial_users[username] update_user( user_id=[ str(uid), ], password=password, ) # set a random password for all other users for name, id in initial_users.items(): if name != username: random_pass = "".join( random.choices( string.ascii_uppercase + string.ascii_lowercase + string.digits + "@$!%*?&-_", k=16, )) update_user( user_id=[ str(id), ],
username, password = read_user_file() initial_users = db_users() if username not in initial_users: # create a new user create_user(username=username, password=password) users = db_users() uid = users[username] roles = db_roles() rid = roles["administrator"] set_user_role( user_id=[ str(uid), ], role_ids=[ str(rid), ], ) else: # modify an existing user ("wazuh" or "wazuh-wui") uid = initial_users[username] update_user( user_id=[ str(uid), ], password=password, ) # disable unused default users for def_user in ['wazuh', 'wazuh-wui']: if def_user != username: disable_user(initial_users[def_user])