【问题标题】:I was trying to make a password cracker and ran into an issue of the program repeating passwords already tried [closed]我试图制作密码破解程序并遇到程序重复密码已经尝试过的问题[关闭]
【发布时间】:2021-10-11 19:15:26
【问题描述】:

这是代码,我正在一个测试网站上使用它。它生成随机密码并将它们保存到文本文件中。 2个问题:第一个是文本文件没有保存所有密码尝试,第二个是它重做以前的密码尝试

  PASSWORD = ""
ATTEMPTS = 0
MaxAttempts = 9999;
driver.get("https://test")
driver.find_element_by_name("login").send_keys("testacc")\

LENGTH = range(8,16)

mouse_pos = pygame.mouse.get_pos()

PASSWORD = ''.join(random.choice(string.ascii_letters + string.digits) for _ in (LENGTH))

with open('Attempts.txt', 'w') as f:
        f.write(PASSWORD)

        if driver.current_url != ("https://test"):
                print(PASSWORD, " is the password")

while(driver.current_url == ('https://test')):


        else:
                with open('Attempts.txt', 'w') as f:
                 f.write(PASSWORD)

        PASSWORD = ''.join(random.choice(string.ascii_letters + string.digits) for _ in (LENGTH))
        driver.find_element_by_name("password").send_keys(PASSWORD)

        ATTEMPTS = ATTEMPTS + 1
        LASTTRIEDPASSWORD = PASSWORD
        print(LASTTRIEDPASSWORD, "This is the ", ATTEMPTS, " Attempt")

【问题讨论】:

  • 这里有很多问题。你的长度没有被选中,你每次都会有 8 个 (len(8,16)) 个字母。您只是从可能的密码中随机选择一个密码,当然它会重复,但我认为您不会发现重复,因为 62^8 是 218 万亿...

标签: python pycharm


【解决方案1】:

我建议您制作一个attempts.py 文件并将密码作为列表存储在其中,例如。 list = []。 然后是用户导入功能,例如。 import attemps 然后attempts.list。当你走得更远时,如果你想添加一些东西,只需使用attempts.list.append(item) 并在您的其他文件(您已导入 requests.py 的文件)中删除 use attempts.list.remove(item)

像这样:(添加)

import attempts

with open('Attempts.py', 'a') as f:
        f.write(f"\nlist.append({PASSWORD})")
        

像这样:(删除)

import attempts

with open('Attempts.py', 'a') as f:
        f.write(f"\nlist.remove({PASSWORD})")
        

像这样:(添加) 这将使用列表中的新密码创建文件,并且会这样做。

import attempts

with open('Attempts.py', 'w') as f:
        f.write("list = []")
        f.write(f"\nlist.append({PASSWORD})")
        

希望能回答这个问题。

【讨论】:

  • 我如何从我的脚本中省略它,自动在该列表中生成密码?
  • 例如,如果您在cracker.py 中创建了一个随机密码并希望程序将该密码添加到尝试.py 然后使用上述方法(添加),如果您想删除该密码尝试使用以下方法(删除)后,就像您所做的是获得随机密码,然后将其写入尝试.txt,但使用尝试.py 执行相同操作,如果您想在列表中一次又一次地添加密码使用with open("attempts.py", "a") as f```` and not with open("attempts.py", "w") as f````,但是如果你想更改完整的文件,请按照第三种方法( To Write )。
  • 但这是否意味着“PASSWORD”变量不会生成该列表中的密码?
  • 这只是意味着 PASSWORD 变量会根据您的代码生成密码,然后将其保存在尝试.py 中或将其删除或您选择执行的任何操作。它没有做任何其他事情。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 1970-01-01
  • 2016-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多