Posted on

I want to harvest passwords from a login form in Python

I want to harvest passwords from a login form - Python:

def harvest_passwords(form):
    Harvest passwords from a login form.

    form : str
        The HTML of the login form.

    list of str
        The passwords found in the form.

    #find all the input fields in the form
    fields = re.findall(r'<input.*?>', form)

    #create a list of passwords
    passwords = []

    #loop over the fields
    for field in fields:

        #check to see if it's a password field
        if "type='password'" in field:

            #get the value of the password
            value = re.findall(r'value="(.*?)"', field)[0]

            #add it to our list

    #return the passwords
    return passwords

form = """
<input type='text' name='username' />
<input type='password' name='password' value='secret' />
<input type='submit' />
result = harvest_passwords(form)
print(result)  #['secret']
Enter fullscreen mode Exit fullscreen mode

Top comments (0)