I want to harvest passwords from a login form - Python:
def harvest_passwords(form):
"""
Harvest passwords from a login form.
Parameters
----------
form : str
The HTML of the login form.
Returns
-------
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
passwords.append(value)
#return the passwords
return passwords
#example
form = """
<input type='text' name='username' />
<input type='password' name='password' value='secret' />
<input type='submit' />
"""
result = harvest_passwords(form)
#output
print(result) #['secret']
Top comments (0)